screen isn't scrolling up when the keyboard appers. I've read many answers saying to use android:windowSoftInputMode="something" I tried many of them
android:windowSoftInputMode="adjustPan|adjustResize"
android:windowSoftInputMode="adjustResize"
android:windowSoftInputMode="adjustPan"
android:windowSoftInputMode="stateVisible|adjustResize"
android:windowSoftInputMode="stateVisible"
(also tried some others) none of them worked
I think the problem is on my xml which the most was generated by android studio "activity login" template.
is there any other way to do it?
my xml file
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.example.eduardo.academia.LoginActivity">
<!-- Login progress -->
<ProgressBar
android:id="#+id/login_progress"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:visibility="gone" />
<ImageView
android:id="#+id/imageView"
android:layout_width="211dp"
android:layout_height="235dp"
app:srcCompat="#drawable/logo"
android:windowSoftInputMode="stateHidden"/>
<LinearLayout
android:id="#+id/login_form"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/email_login_form"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<AutoCompleteTextView
android:id="#+id/email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/prompt_email"
android:inputType="textEmailAddress"
android:maxLines="1"
android:singleLine="true" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/prompt_password"
android:imeActionId="#+id/login"
android:imeActionLabel="#string/action_sign_in_short"
android:imeOptions="actionUnspecified"
android:inputType="textPassword"
android:maxLines="1"
android:singleLine="true" />
</android.support.design.widget.TextInputLayout>
<Button
android:id="#+id/email_sign_in_button"
style="?android:textAppearanceSmall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="#string/action_sign_in"
android:textStyle="bold" />
<TextView
android:id="#+id/txtMudarSenha"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:gravity="center"
android:text="#string/forgot_password"
android:onClick="mudarSenha"
android:clickable="true"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
android manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.eduardo.academia">
<!-- To auto-complete the email text field in the login form with the user's emails -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:windowSoftInputMode="stateVisible|adjustResize"
android:name=".LoginActivity"
android:label="#string/title_activity_login"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ExerciciosActivity"
android:label="#string/title_activity_exercicios"
android:theme="#style/AppTheme.NoActionBar"></activity>
</application>
</manifest>
You should use a ScrollView for this. try below xml for your layout
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.example.eduardo.academia.LoginActivity">
<!-- Login progress -->
<ProgressBar
android:id="#+id/login_progress"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:visibility="gone" />
<ImageView
android:id="#+id/imageView"
android:layout_width="211dp"
android:layout_height="235dp"
app:srcCompat="#drawable/logo"
android:windowSoftInputMode="stateHidden"/>
<LinearLayout
android:id="#+id/login_form"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/email_login_form"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<AutoCompleteTextView
android:id="#+id/email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/prompt_email"
android:inputType="textEmailAddress"
android:maxLines="1"
android:singleLine="true" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/prompt_password"
android:imeActionId="#+id/login"
android:imeActionLabel="#string/action_sign_in_short"
android:imeOptions="actionUnspecified"
android:inputType="textPassword"
android:maxLines="1"
android:singleLine="true" />
</android.support.design.widget.TextInputLayout>
<Button
android:id="#+id/email_sign_in_button"
style="?android:textAppearanceSmall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="#string/action_sign_in"
android:textStyle="bold" />
<TextView
android:id="#+id/txtMudarSenha"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:gravity="center"
android:text="#string/forgot_password"
android:onClick="mudarSenha"
android:clickable="true"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
Related
I am new to Android Studio and can't seem to fix my app not fitting on my screen. I'm using Honor 8 for testing how the app looks and works but parts don't fit. I have tried including activity_main for different screen densities and and screen sizes, but nothing seems to work. Would appreciate some help.
Can not include images yet so here is manifest and activity_main.xml.
activity_main.xml:
`
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:id="#+id/parent">
<RelativeLayout
android:id="#+id/imageRel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_margin="5dp"
android:layout_alignParentTop="true">
<ImageView
android:id="#+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:minWidth="100dp"
android:minHeight="100dp"
android:src="#mipmap/ic_launcher" />
<Button
android:id="#+id/imgButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="20dp"
android:layout_toRightOf="#+id/image"
android:text="Press" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/inputRel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/imageRel"
android:layout_margin="20dp">
<EditText
android:id="#+id/nameTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:width="170dp"
android:hint="Name" />
<EditText
android:id="#+id/emailTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/nameTxt"
android:layout_margin="10dp"
android:width="170dp"
android:hint="Email" />
<EditText
android:id="#+id/passwordTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/emailTxt"
android:layout_margin="10dp"
android:width="170dp"
android:password="true"
android:hint="Password" />
<EditText
android:id="#+id/reenterTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/passwordTxt"
android:layout_margin="10dp"
android:width="170dp"
android:password="true"
android:hint="Re-Enter Password" />
<TextView
android:id="#+id/genderTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/reenterTxt"
android:layout_margin="10dp"
android:text="Gender:" />
<RadioGroup
android:id="#+id/radioGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/genderTxt"
android:layout_margin="10dp"
android:orientation="horizontal">
<RadioButton
android:id="#+id/radioMale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="Male" />
<RadioButton
android:id="#+id/radioFemale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Female" />
<RadioButton
android:id="#+id/radioOther"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Other" />
</RadioGroup>
<TextView
android:id="#+id/countryTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/radioGroup"
android:layout_margin="10dp"
android:text="Country:" />
<Spinner
android:id="#+id/countrySpinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/radioGroup"
android:layout_margin="10dp"
android:layout_toRightOf="#+id/countryTxt"
android:textColor="#000000" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/licenseRel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:layout_toRightOf="#+id/inputRel"
android:layout_centerVertical="true">
<TextView
android:id="#+id/licenseTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/license_text" />
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/licenseCheck"
android:layout_below="#+id/licenseTxt"
android:layout_centerHorizontal="true"
android:text="I Agree" />
</RelativeLayout>
<Button
android:id="#+id/registerButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="Register"
android:layout_below="#id/inputRel"/>
</RelativeLayout>`
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.RegistrationApp">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
I know this question has been on the internet for ages, but nothing seems to work in my case.
What's wrong
As seen in screenshots, the layout having the spinner is not pushed up and is overlapped by the soft keyboard. I want this layout to be placed just above the keyboard when it pops up.
My layout file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/white"
android:orientation="vertical"
tools:context="believe.cht.speak.MainActivity">
<ImageView
android:id="#+id/logo"
android:layout_width="64dp"
android:layout_height="64dp"
android:layout_gravity="center_horizontal"
android:layout_margin="16dp"
android:src="#drawable/ic_bubble"
android:tint="#color/blue" />
<EditText
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#android:color/transparent"
android:gravity="top|start"
android:hint="Start typing..."
android:padding="8dp" />
<ImageView
android:id="#+id/shadow"
android:layout_width="match_parent"
android:layout_height="6dp"
android:src="#drawable/shadow" />
<RelativeLayout
android:id="#+id/spinnerLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="#color/blue">
<Spinner
android:id="#+id/spinner"
android:layout_width="200dp"
android:layout_height="48dp"
android:layout_alignParentEnd="true" />
</RelativeLayout>
</LinearLayout>
What I've tried
android:windowSoftInputMode="adjustResize"
android:windowSoftInputMode="adjustPan" //in the manifest, also tried combining the two
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN); //in the activity
<item name="android:windowActionBarOverlay">true</item> //in styles.xml
Try this
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/white"
android:orientation="vertical">
<ImageView
android:id="#+id/logo"
android:layout_width="64dp"
android:layout_height="64dp"
android:layout_gravity="center_horizontal"
android:layout_margin="16dp"
android:src="#drawable/ic_message" />
<EditText
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#android:color/transparent"
android:gravity="top|start"
android:hint="Start typing..."
android:padding="8dp" />
<ImageView
android:id="#+id/shadow"
android:layout_width="match_parent"
android:layout_height="6dp"
android:src="#drawable/ic_camera" />
<RelativeLayout
android:id="#+id/spinnerLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="#color/colorPrimary">
<Spinner
android:id="#+id/spinner"
android:layout_width="200dp"
android:layout_height="48dp"
android:layout_alignParentEnd="true" />
</RelativeLayout>
</LinearLayout>
</ScrollView>
Manifest file
<activity android:name=".MyActivity"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
OUTPUT
Adding to Nilesh's answer above, even though the code worked, it didn't work with my Java class. The reason was that I was hiding the statusbar with
requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
Using the code provided and leaving the statusbar untouched did the job. Don't know why. I would be helpful if anyone could explain this.
Try using a RelativeLayout instead of LinearLayout and add android:alignParentBottom="true" to your spinnerLayout
this is my xml file layout when keyboard is open my bottom view also scroll
<ScrollView
android:id="#+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<LinearLayout
android:id="#+id/linear2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:isScrollContainer="false"
android:orientation="vertical">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/edt_education_school"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="#dimen/_14sdp"
android:textColor="#2e2e2e"
android:imeOptions="actionNext"
android:hint="School Name" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<EditText
android:id="#+id/edt_education_degree"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#2e2e2e"
android:textSize="#dimen/_14sdp"
android:imeOptions="actionNext"
android:hint="Degree" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/edt_education_field_of_study"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#2e2e2e"
android:textSize="#dimen/_14sdp"
android:imeOptions="actionNext"
android:hint="Field Of Study" />
</android.support.design.widget.TextInputLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="2">
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:orientation="vertical"
android:layout_height="wrap_content"
>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/edt_education_start_date"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Start Date"
android:inputType="number"
android:textColor="#2e2e2e"
android:imeOptions="actionNext"
android:textSize="#dimen/_14sdp" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:orientation="vertical"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/edt_education_end_date"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="End Date"
android:inputType="number"
android:textColor="#2e2e2e"
android:imeOptions="actionNext"
android:textSize="#dimen/_14sdp" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
</LinearLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/edt_education_activities"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#2e2e2e"
android:textSize="#dimen/_14sdp"
android:imeOptions="actionNext"
android:hint="Activities" />
</android.support.design.widget.TextInputLayout>
<Button
android:id="#+id/btn_education_save"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#drawable/button_selector"
android:text="Save"
android:visibility="gone"
android:textColor="#color/white" />
</LinearLayout>
</ScrollView>
<TextView
android:id="#+id/tv_delete_education"
android:layout_width="match_parent"
android:layout_height="#dimen/_30sdp"
android:layout_alignParentBottom="true"
android:layout_marginTop="#dimen/_10sdp"
android:gravity="center"
android:visibility="gone"
android:textColor="#222222"
android:textSize="#dimen/_16sdp"
android:text="Delete Education" />
when i open the keyboard my textview (tv_delete_education) is override on text
i want to fix my textview in bottom navigation no required to scroll. i also add in menifest file adjustPan ,adjustResize but still not work for me if any kind of help let me know thanks in advance
use this in android manifest android:windowSoftInputMode="adjustNothing"
for activity.It will solve your problem.
Here is basic format for your design and its working.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.whiz_010.myapplication.ui.home.MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Title"
/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Company"
/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Location"
/>
</android.support.design.widget.TextInputLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="2">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Start Date"
/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="End Date"
/>
</android.support.design.widget.TextInputLayout>
</LinearLayout>
</LinearLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="15dp"
android:text="Delete Experience"
android:textSize="20sp"
android:textStyle="bold" />
</FrameLayout>
</RelativeLayout>
AndroidManifest.xml
<activity
android:name=".ui.home.MainActivity"
android:windowSoftInputMode="adjustPan"/>
I don't know how to get my soft keyboard to show up under an TextView Field. It just covers up my Button and TextView.
I have used this link http://android-developers.blogspot.com/2009/04/updating-applications-for-on-screen.html
as a reference. But it isn't working.
I have windowSoftInputMode="adjustPan" in the AndroidManifest file for my activity
<activity
android:name=".SearchView"
android:label="#string/title_activity_search_view"
android:parentActivityName=".MainActivity"
android:theme="#style/AppTheme.NoActionBar"
android:windowSoftInputMode="adjustPan">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.txisystems.inventory.MainActivity" />
</activity>
Here is what the screen looks like without the soft keyboard.
and the code to go with it.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.mycompany.inventory.SearchView"
tools:showIn="#layout/activity_search_view">
<ImageView
android:id="#+id/logoView"
android:layout_width="225dp"
android:layout_height="90dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="20dp"
android:src="#drawable/mylogo" />
<ProgressBar
android:id="#+id/progressBar2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/logoView"
android:layout_centerHorizontal="true"
android:visibility="invisible" />
<EditText
android:id="#+id/txtSearchField"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="#+id/logoView"
android:layout_alignLeft="#+id/logoView"
android:layout_alignRight="#+id/logoView"
android:layout_alignStart="#+id/logoView"
android:layout_below="#+id/progressBar2"
android:inputType="textShortMessage"
android:maxLength="17"
android:maxLines="1"
android:capitalize="none" />
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/txtSearchField"
android:layout_marginBottom="15dp"
android:layout_marginTop="10dp"
android:background="#color/colorPrimary"
android:backgroundTint="#color/colorPrimaryDark"
android:onClick="doSearch"
android:text="Search"
android:textColor="#color/buttontext" />
<TextView
android:id="#+id/lblSearchMessage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="#+id/button"
android:layout_alignLeft="#+id/button"
android:layout_alignRight="#+id/button"
android:layout_alignStart="#+id/button"
android:layout_below="#+id/button"
android:gravity="center_horizontal"
android:text="Please enter 4 or more characters."
android:textAllCaps="true"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/error"
android:textStyle="bold" />
</RelativeLayout>
Here is what happens (I used Photoshop to simulate the screen.)
The keyboard can't be dismissed and it covers the button and the message area.
And here is what I want to happen through the magic of Photoshop.
Use this in the Activity (OnCreate) which hosts the XML:
getActivity().getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
I build two XML-files for my activity. One in the layout Folder and the other in the layout-land folder. But when I change the orientation from portrait to landscape mode the activity relaunches. And thats exactly what i not want.
Because I'm plotting in three Graphs realtime data and the plotting should continue when I turn the Screen and not being interrupted or start new in any way.
Here is the first XML file in the layout-land Folder:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="496dp"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:id="#+id/my_layout" >
<com.jjoe64.graphview.GraphView
android:id="#+id/sensor1_graph_Feuchtigkeit"
android:layout_width="match_parent"
android:layout_height="270dp"
android:layout_alignLeft="#+id/sensor1_graph_Druck"
android:layout_alignParentTop="true" />
<com.jjoe64.graphview.GraphView
android:id="#+id/sensor1_graph_Temperatur"
android:layout_width="match_parent"
android:layout_height="270dp"
android:layout_alignLeft="#+id/sensor1_graph_Feuchtigkeit"
android:layout_below="#+id/sensor1_graph_Feuchtigkeit"
android:layout_marginTop="8dp" />
<com.jjoe64.graphview.GraphView
android:id="#+id/sensor1_graph_Druck"
android:layout_width="match_parent"
android:layout_height="270dp"
android:layout_below="#+id/sensor1_graph_Temperatur"
android:layout_centerHorizontal="true"
android:layout_marginTop="8dp" />
<Switch
android:id="#+id/mySwitch"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_below="#+id/sensor1_graph_Druck"
android:layout_centerHorizontal="false"
android:layout_marginTop="8dp"
/>
<TextView
android:id="#+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/switchStatus"
android:layout_alignParentBottom="true"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/switchStatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/mySwitch"
android:layout_alignBottom="#+id/mySwitch"
android:layout_marginLeft="15dp"
android:layout_toRightOf="#+id/mySwitch"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Switch
android:id="#+id/switch1"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_alignLeft="#+id/mySwitch"
android:layout_alignParentBottom="true"
/>
</RelativeLayout>
</ScrollView>
And here the second one in layout Folder:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="496dp"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:id="#+id/my_layout" >
<com.jjoe64.graphview.GraphView
android:id="#+id/sensor1_graph_Feuchtigkeit"
android:layout_width="match_parent"
android:layout_height="130dp"
android:layout_alignLeft="#+id/sensor1_graph_Druck"
android:layout_alignParentTop="true" />
<com.jjoe64.graphview.GraphView
android:id="#+id/sensor1_graph_Temperatur"
android:layout_width="match_parent"
android:layout_height="130dp"
android:layout_alignLeft="#+id/sensor1_graph_Feuchtigkeit"
android:layout_below="#+id/sensor1_graph_Feuchtigkeit"
android:layout_marginTop="8dp" />
<com.jjoe64.graphview.GraphView
android:id="#+id/sensor1_graph_Druck"
android:layout_width="match_parent"
android:layout_height="130dp"
android:layout_below="#+id/sensor1_graph_Temperatur"
android:layout_centerHorizontal="true"
android:layout_marginTop="8dp" />
<Switch
android:id="#+id/mySwitch"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_below="#+id/sensor1_graph_Druck"
android:layout_centerHorizontal="false"
android:layout_marginTop="8dp"
/>
<TextView
android:id="#+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/switchStatus"
android:layout_alignParentBottom="true"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/switchStatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/mySwitch"
android:layout_alignBottom="#+id/mySwitch"
android:layout_marginLeft="15dp"
android:layout_toRightOf="#+id/mySwitch"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Switch
android:id="#+id/switch1"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_alignLeft="#+id/mySwitch"
android:layout_alignParentBottom="true"
/>
</RelativeLayout>
</ScrollView>
In the Manifest XML it Looks like this:
<activity
android:name="com.TomKun.testgraph.DruckActivity"
android:label="#string/Sensor_1"
android:launchMode="singleTask"
android:configChanges="orientation|screenSize|keyboard|keyboardHidden">
</activity>
If i have Manifest like this with
android:configChanges="orientation|screenSize|keyboard|keyboardHidden">
</activity>
Then the layout does not change when I switch from Portrait to landscape mode. BUT the activity does not relaunch. Thats the one good thing
But if I do NOT use
android:configChanges="orientation|screenSize|keyboard|keyboardHidden">
</activity>
the layout changes as i want but the activity is then relaunching.
So something in my implementation doesn't match.
Can anyone help me to solve this Problem?
I have seen that many people have similar Problems here on stackoverflow. But with these answers I couldn't solve my problem
Thanks in Advance!