EditText disappears on Android Marshmallow 6.0 devices - android

This is how my xml layout file in IDE looks like:
It looks like that on every device BUT Marshmallow ones, which ended up looking like this:
As you can see, the password EditText and Remember CheckBox disappeared without a trace, yet I still can declare them in the class file normally.
This is my xml file:
<?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:id="#+id/activity_log_in"
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"
tools:context="my.app.LogInActivity">
<!-- Dummy item to prevent AutoCompleteTextView from receiving focus -->
<LinearLayout
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_width="0px"
android:layout_height="0px"
android:id="#+id/linearLayout5"
android:orientation="horizontal" />
<!-- :nextFocusUp and :nextFocusLeft have been set to the id of this component
to prevent the dummy from receiving focus again -->
<AutoCompleteTextView android:id="#+id/autotext"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:nextFocusUp="#id/autotext"
android:visibility="invisible"
android:nextFocusLeft="#id/autotext"
android:textSize="15sp" />
<TextView
android:id="#+id/txtname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/txt_customer"
android:layout_alignBottom="#+id/txt_customer"
android:text="Name"
android:textSize="14sp" />
<EditText
android:id="#+id/txt_customer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_below="#+id/autotext"
android:layout_toEndOf="#+id/bt_exit"
android:ems="10"
android:imeOptions="flagNoExtractUi"
android:inputType="textPersonName"
android:maxLength="100"
android:textSize="15sp" />
<EditText
android:id="#+id/txt_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textView2"
android:layout_alignBottom="#+id/textView2"
android:layout_alignParentEnd="true"
android:layout_alignStart="#+id/txt_customer"
android:ems="10"
android:imeOptions="flagNoExtractUi"
android:inputType="textPassword"
android:maxLength="100"
android:textSize="15sp" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/txtname"
android:layout_alignStart="#+id/txtname"
android:layout_below="#+id/txt_customer"
android:layout_marginTop="25dp"
android:text="Pasword"
android:textSize="14sp" />
<Button
android:id="#+id/bt_login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:text="LogIn"
android:textColor="#000000" />
<Button
android:id="#+id/bt_exit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_toEndOf="#+id/linearLayout5"
android:text="Quit"
android:textColor="#000000" />
<CheckBox
android:id="#+id/check_remember"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="#+id/txt_password"
android:layout_below="#+id/txt_password"
android:text="Remember" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/linearLayout5"
android:layout_toEndOf="#+id/linearLayout5"
android:text="Log In" />
The Name EditText and Password EditText are the same yet only the Password one disappears on Marshmallow 6.0 devices. I have already tried to change theme, Build Target, position but it's still the same. What had go wrong?
EDIT #1:This question mentioned "messy code" and it was solved by "cleaning up" the code. I am using RelativeLayout as parent like him, but changing to LinearLayout isn't viable.
EDIT #2: I tried to preset a value just to login, and it worked normally like I just typed it in manually. Inside layouts file are the same: Only one EditText appears, the rest (EditText, CheckBox, RadioButtons) disappear. What is going on?? Example:
On Marshmallow:

Solved the disappearing bug. From this SO answer which leads me to this Google issue. I have to delete android:layout_alignBaseline attribute and they will render fine.

Related

How to move a button above the keyboard?

This question has been asked before, but I can't find a good answer that works for me.
Here is my XML code (updated):
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Account Name"
android:textSize="32dp"
android:layout_marginTop="15dp"
android:layout_marginLeft="15dp"
android:id="#+id/textView" />
<EditText
android:layout_width="match_parent"
android:layout_height="40dp"
android:id="#+id/accountName"
android:background="#drawable/edit_text_background"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:padding="10dp"
android:backgroundTint="#color/abc_secondary_text_material_light" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Account Balance"
android:textSize="32dp"
android:layout_marginTop="15dp"
android:layout_marginLeft="15dp"/>
<EditText
android:layout_width="match_parent"
android:layout_height="40dp"
android:inputType="numberDecimal"
android:id="#+id/accountBalance"
android:background="#drawable/edit_text_background"
android:layout_marginRight="15dp"
android:layout_marginLeft="15dp"
android:padding="10dp"
android:backgroundTint="#color/abc_secondary_text_material_light"
android:text="£"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:text="New Button"
android:id="#+id/button"
android:layout_gravity="center_horizontal"
android:layout_alignParentBottom="true"
/>
</RelativeLayout>
I've tried using android:windowSoftInputMode="adjustPan|adjustResize" however it hasn't worked.
I feel I'm doing something wrong with the layout of the XML code... It looks like this and I want the button to move up when the keyboard appears:
try using ScrollView at parent level
<ScrollView
android:id="#+id/login_form"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
in your AndroidManifest.xml
android:windowSoftInputMode="stateVisible|adjustResize"
in style.xml file set your activity style as
<item name="android:windowActionBarOverlay">true</item>
make sure you are not using fullscreen activity.
I struggled with the same thing for long. The solution worked for me is by
adding below line to activity manifest.
android:windowSoftInputMode="stateHidden"
I request to keep the layout inside scrollview except the view(Button in this ques case) which you want move with keyboard.

Software keyboard move editTexts for android

I'm trying to get the editTexts, and sign in button to move up when the software keyboard is out however I want the background to not be compressed(I'm going to add an image soon). I have the TextView(Login), two EditTexts(email and password) and signin button in a ScrollView because I thought that might help however I have not be able to figure anything out.
http://i.imgur.com/vlYifc6.png
http://i.imgur.com/vlYifc6.png
This is the xml
<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"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".MainActivity">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/scrollView"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" >
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:gravity="center"
android:id="#+id/textLayout">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Login"
android:id="#+id/loginView"
android:textSize="22dp"
android:layout_above="#+id/textLayout"
android:layout_centerHorizontal="true" />
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/emailTextfield"
android:inputType="textEmailAddress"
android:background="#android:drawable/edit_text"
android:textColor="#android:color/primary_text_light"
android:text="andresc1305#yahoo.com"
android:hint="Email" />
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:hint="Password"
android:text="Andres123"
android:background="#android:drawable/edit_text"
android:textColor="#android:color/primary_text_light"
android:ems="10"
android:id="#+id/passwordTextfield" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SIGN IN"
android:background="#android:color/transparent"
android:textSize="24dp"
android:id="#+id/signinButton"
android:layout_below="#+id/textLayout"
android:layout_centerHorizontal="true"
android:onClick="onSigninClick"/>
</LinearLayout>
</ScrollView>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Forgot your password?"
android:background="#android:color/transparent"
android:textSize="14dp"
android:id="#+id/forgotButton"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:onClick="onPasswordRecoverClick"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Register"
android:background="#android:color/transparent"
android:textSize="14dp"
android:id="#+id/registerButton"
android:layout_alignTop="#+id/forgotButton"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:onClick="onRegisterClick"/>
</RelativeLayout>
Look at this answer. In short, your problem can most likely be solved by setting the following in your AndroidManifest.xml inside the relevant activity or application element:
android:windowSoftInputMode="adjustResize"
#PPartisan
This is without:
android:windowSoftInputMode="adjustResize"
http://i.imgur.com/tbNioU2.png
This is with:
http://i.imgur.com/7ZePHjS.png
Beside the compression you can see my "Forgot your password" and "Register" buttons but I have those outside my ScrollView in the XML. Is there a way to scroll the LinearLayout (which contains the Login(TextView, email(EditText), password(EditText), and Signin(button) up when the software keyboard comes up?
The answer by zmilojko seems like what I want to do but he only says to add the ScrollView and not what to do after that has been added. Is there something I can place in the to make it move up when the software keyboard comes up?
see this thread, i think it can help you
layout of the screen moves up when keyboard is displayed
or just try to put this in your xml:
android:windowSoftInputMode="adjustPan"
or this
android:windowSoftInputMode="adjustNothing"
Seems like it works different in each case.

How to set position:fixed in android?

In my app, there is a login and password field near the middle of the screen. I have this in the manifest
android:windowSoftInputMode="adjustResize|stateHidden"
So that the fields are still visible when the keyboard is showing. But the problem is, there is a textview that is bottom aligned, and when the keyboard shows, this view overlaps with the login button under the username/password fields, is there a way, so set that textview field to not be affected by the adjestResize?
Thanks.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/credentailsLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/background_home"
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=".ActivityHome" >
<ImageView
android:id="#+id/imageLogo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/username"
android:layout_alignParentTop="true"
android:layout_marginBottom="50dp"
android:layout_marginTop="10dp"
android:scaleType="centerInside"
android:contentDescription="#+strings/logoimage"
android:src="#drawable/logo_2_scale" />
<EditText
android:id="#+id/username"
android:layout_width="480dp"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginBottom="10dp"
android:layout_centerInParent="true"
android:background="#drawable/bg_edit_text"
android:gravity="center"
android:hint="#string/login_username"
android:inputType="textEmailAddress"
android:text="#string/DEBUG_login_username"
android:textColor="#000000" >
</EditText>
<EditText
android:id="#+id/password"
android:layout_width="480dp"
android:layout_height="wrap_content"
android:layout_below="#+id/username"
android:layout_marginBottom="10dp"
android:layout_centerInParent="true"
android:background="#drawable/bg_edit_text"
android:gravity="center"
android:hint="#string/login_password"
android:inputType="textPassword"
android:text="#string/DEBUG_login_password"
android:textColor="#000000" />
<Button
android:id="#+id/logInMode"
style="#style/loginButtonStyle"
android:layout_width="480dp"
android:layout_height="43dp"
android:layout_below="#+id/password"
android:layout_centerInParent="true"
android:background="#drawable/button_selector"
android:gravity="center"
android:onClick="ValidateLogin"
android:text="#string/loginonline" />
<TextView
android:id="#+id/advancedMenu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_gravity="bottom"
android:background="#drawable/advmenu_button_selector"
android:clickable="true"
android:gravity="center"
android:onClick="ShowAdvancedMenu"
android:paddingBottom="3dp"
android:paddingLeft="3dp"
android:paddingRight="3dp"
android:paddingTop="2dp"
android:text="#string/advancedmenu"
android:textColor="#FFFFFF"
android:textSize="17sp" />
</RelativeLayout>
EDIT:
Apparently a member of the Android team said there is no direct way to do this. I searched for "android check if keyboard is visible" on Google and got the following answered question:
How do I Detect if Software Keyboard is Visible on Android Device?
According to the linked answer, you can detect it indirectly by checking if the window size changed in #onMeasure. See How to check visibility of software keyboard in Android?

Edittext loses style when align_baseline used

I have a layout where I have RelativeLayout with some Edittext which use the default style and are baseline aligned with some Textfield. The issue is the Edittext are losing the default Holo Light style line (the line under the text). If I take out the baseline then the line is shown though, of course, the Edittext loses the alignment.
I suspect this is bug or at least a very strange behavior, but I will give it a try by asking here in SO :-)
This is how it looks (Edittexts are the blank spaces to the right of Opens and Closes TextViews):
This is my layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_height="match_parent"
android:layout_width="0dip"
android:layout_weight="50"
android:orientation="vertical" >
<EditText
android:id="#+id/store_name_edit"
android:hint="#string/store_name"
android:layout_height="wrap_content"
android:layout_width="match_parent" />
<EditText
android:id="#+id/store_code_edit"
android:hint="#string/store_code"
android:layout_height="wrap_content"
android:layout_width="match_parent" />
<EditText
android:id="#+id/store_group_edit"
android:hint="#string/store_group"
android:layout_height="wrap_content"
android:layout_width="match_parent" />
<EditText
android:id="#+id/store_type_edit"
android:hint="#string/store_type"
android:layout_height="wrap_content"
android:layout_width="match_parent" />
<EditText
android:id="#+id/store_address_edit"
android:hint="#string/store_street"
android:layout_height="wrap_content"
android:layout_width="match_parent" />
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:paddingTop="20dip"
android:textSize="20sp"
android:text="#string/store_description" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/opening"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:text="#string/store_opening_hours" />
<TextView
android:id="#+id/opens"
android:layout_below="#id/opening"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:text="#string/store_open" />
<EditText
android:id="#+id/opens_edit"
android:layout_toRightOf="#id/opens"
android:layout_alignBaseline="#id/opens"
android:layout_height="wrap_content"
android:layout_width="100dip"
android:textSize="18sp" />
<TextView
android:id="#+id/closes"
android:layout_alignBaseline="#id/opens"
android:layout_toRightOf="#id/opens_edit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:text="#string/store_close" />
<EditText
android:id="#+id/closes_edit"
android:layout_alignBaseline="#id/opens"
android:layout_toRightOf="#id/closes"
android:layout_height="wrap_content"
android:layout_width="100dip"
android:textSize="18sp" />
</RelativeLayout>
</LinearLayout>
My guess is the containing RelativeLayout somehow isn't expanding to allow for the lines on the EditTexts to show.
Change the containing RelativeLayout to:
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="100dp">
I realise this may not be the best solution but it's a start. Another option might be to try using alignParentBottom instead of baseline on all the "bottom" row elements.

Android: EditText stays hidden behind the keyboard

Before writing this question I have read through the following answers/articles:
Android soft keyboard covers edittext field
Android keyboard obscures EditText
http://developer.android.com/resources/articles/on-screen-inputs.html
Soft Keyboard Overlapping with EditText Field
The Android soft keyboard is set by default to pan which means it will keep all the editable regions above the keyboard. However it does not pan enough. When I run it and press the edittext that is close to the bottom of the screen, the keyboard comes up and edittext is moved up but not enough to be able to see what is being typed in it. I have used/tried the following:
android:windowSoftInputMode="adjustPan" in the manifest of the Activity. This made no difference. I have also tried putting values of adjustUnspecified and adjustResize too. None of them works.
<uses-sdk android:minSdkVersion="3" /> in the manifest file. My application is targetted for sdk 2.1 and above. Even though, I tried it and did not work.
Using a ScrollView. Does not work either.
Is there a way to manually manage how much "panning" does a keyboard do when a specific edittext is pressed.
Below is my xml file.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff">
<ImageView
android:id="#+id/header"
android:layout_width="320dip"
android:layout_height="86dip"
android:background="#drawable/header_bg">
</ImageView>
<ImageView
android:layout_width="320dip"
android:layout_height="200dip"
android:layout_alignParentBottom="true"
android:background="#drawable/bg1_btm">
</ImageView>
<TextView android:text="Hostname"
android:id="#+id/lbl_hostname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/header"/>
<TextView android:text="(Current)"
android:id="#+id/lbl_hostname_current"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/lbl_hostname"
android:layout_below="#id/header" />
<EditText android:text="EditText"
android:id="#+id/editText_hostname"
android:layout_below="#id/lbl_hostname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLength="25">
</EditText>
<TextView android:text="Registration URL"
android:id="#+id/lbl_registration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/editText_hostname" />
<TextView android:text="(Current)"
android:id="#+id/lbl_registration_current"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/editText_hostname"
android:layout_toRightOf="#id/lbl_registration" />
<TextView android:text="http://"
android:id="#+id/lbl_url_prefiz"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/lbl_registration"
android:paddingTop="10dip" />
<EditText android:text="EditText"
android:id="#+id/editText_registration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf ="#id/lbl_url_prefiz"
android:layout_below="#id/lbl_registration">
</EditText>
<TextView android:text="Chat"
android:id="#+id/lbl_chat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/editText_registration"/>
<TextView android:text="(Current)"
android:id="#+id/lbl_chat_current"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/editText_registration"
android:layout_toRightOf="#id/lbl_chat"/>
<EditText android:text="EditText"
android:id="#+id/editText_chat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/lbl_chat">
</EditText>
<TextView android:text="SSID"
android:id="#+id/lbl_ssid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/editText_chat" />
<TextView android:text="(Current)"
android:id="#+id/lbl_ssid_current"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/editText_chat"
android:layout_toRightOf="#id/lbl_ssid"
/>
<EditText android:text="EditText"
android:id="#+id/editText_ssid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/lbl_ssid"
android:maxLines="1"
android:inputType="text"
android:layout_marginBottom="25dip">
</EditText>
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/ButtonSave"
android:text="Save"
android:layout_below="#id/editText_ssid"
android:layout_alignParentLeft="true">
</Button>
<Button android:text="Continue"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="#+id/ButtonContinue"
android:layout_below="#id/editText_ssid"
android:layout_alignParentRight="true">
</Button>
</RelativeLayout>
Try
android:windowSoftInputMode="adjustResize"
worked fine for me :)
Try to set your all controls layout heights and widths using fill_parent or match_parent...instead of using hard coded values...
also remove this if you are using this as it might be pushing your app downwards...
getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
hope it works...

Categories

Resources