In Android Nougat, the EditText loses focus when the keyboard is displayed. This is working fine with all the lower versions.
I am using requestFocus() manually to get the focus to the EditText and programmatically showing the keyboard. The EditText is placed inside a ListView.
Could someone help me to resolve the issue?
If you can replace ListView with RecyclierView easily, that would be my suggestion. It worked for me.
Try:
Add android:descendantFocusability="afterDescendants" to your ListView.
Add android:focusable="true" and android:focusableInTouchMode="true" to your EditText.
Add android:windowSoftInputMode="adjustPan" to your Activity in AndroidManifest file.
Related
I've been through n number of solutions for this problem and tried them all but nothing helped.
I have an EditText and onClick of it, a custom keyboard appears but the EditText doesn't comes up above the keyboard.
I have tried putting:
android:windowSoftInputMode="stateAlwaysHidden|adjustPan|adjustResize"
in my Manifest file.
I read somewhere that its a bug and it does not work in FULLSCREEN mode so I removed fullscreen mode from my manifest. Again didn't work.
Please help scrolling my EditText up :D
P.S: Please don't answer for android's default keyboard. I am using my own custom keyboard.
In scrollView use the following code:
in XML:
android:fillViewport="true"
OR
in Java:
setFillViewport(true);
You have to use a translate animation, to move the Edit-text or the entire view above the keyboard along with the Y-axis.
As you are using a custom keyboard,no other way seems to be possible.
Even i put scrollview or not, when my edit text request focus and keyboard appears, my view automatically scrolled to top a little bit. It breaks my design. I have to prevent this.
Could you please help me?
Addthis
android:windowSoftInputMode="adjustPan"
android:isScrollContainer="false"
in the manifest file
Add this line in your Manifext.xml under your activity tag and make sure your activity must not use android:theme="#android:style/Theme.Black.NoTitleBar.Fullscreen".
android:windowSoftInputMode="adjustResize"
Please try it and let me know your comments if still you have problem..!!
i would like to know how can i change the layout of the EditText and the "Done" button! Thanks!
PS. This Soft Keyboard has been changed to include Keys i need from the Sample provided by android sdk.
You can try creating your own layout and showing it on Edittext instead.
I have searched and searched for an answer to this question and everything that looked like an answer has not worked so I guess I will just ask.
I have a couple of EditText boxes added to a ListView that is the basis to a ListActivity. When I set the windowSoftInputMode to adjustPan and click in an EditText it works until you click on it again and then the keyboard covers it up. When I use adjustResize it works except when the keyboard comes up the EditText loses focus and I have to tap on it again to type.
I was trying to figure out how to catch the onResize but that seems to be associated with the View and not the activity and I'm not entirely sure how to listen for it. I have also tried all sorts of focusable settings on the EditText boxes and the ListView itself (as suggested in other posts I read) that don't seem to help either.
All you really need to do is apply this to your ListView:
XML:
android:descendantFocusability="afterDescendants"
Java:
listView.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);
For me a combination of the following helped me (especially number 3):
1) Add the following to the related Activity in the manifest file, this is required for your ListView to be resized to fill only the area above the softKeyboard:
android:windowSoftInputMode="adjustResize"
2) With the below the ListView will ONLY get focus only if none of its descendants want it. The descendants (the EditText) needs to get and keep focus.
<ListView
...
android:descendantFocusability="afterDescendants"/>
3) The automatic showing/hiding of the Spelling Suggestions bar right above the keyboard keeps triggering the ListView to refresh. I turned the Suggestions off for any EditText in my ListView.
<EditText
...
android:inputType="textNoSuggestions|textVisiblePassword" />
In my case it perfect worked with adding this like of code to manifest:
android:windowSoftInputMode="adjustPan"
recycler view works best and no need to mess around with any other properties anywhere.
mViewHolder.editText = (EditText)convertView.findViewById(R.id.editText1);
mViewHolder.editText.setTag(position);
mViewHolder.editText.setTextColor(0xFF000000);
mViewHolder.editText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
public void onFocusChange(View v, boolean hasFocus) {
if (!hasFocus) {
EditText et =(EditText)v.findViewById(R.id.editText1);
editTextArrayList.set(position,et.getText().toString().trim());
}
}
});
Hi below link may help for you http://mylearnandroid.blogspot.in/2014/06/listview-problem-while-scrolling.html
Have you tried after you do adjustResize making sure to reset the focus to the EditText by doing something like EditText.requestFocus(); so that it has focus again and the user doesn't have to tap it again. you can use EditText.isFocused() to see if it is focused (true) or not (false) in a debugging log statement or something as well.
you might need to set the field to focusable as well using SetFocusable() but be careful because this could potentially take away the focus from the ListView itself and prevent you from being able to scroll or select things later so you will have to play around with the setting focusable and is focused stuff.
I have experienced exactly the same issue in my project.
To resolve the issue I have subclassed the EditText and handled the "Back" button press - to make sure that my EditTextclears focus at that moment.
Check this solution, on how to do it.
Good luck.
I have an activity with one EditText where I need to input numbers only.
Now, I have defined the Input Type for my EditText to be number only and have drawn up a pretty keypad for my user to use, however I also need to make sure the soft keyboard doesn't pop up for my user when they click on the EditText.
I have tried hiding the keyboard through the manifest by adding
android:windowSoftInputMode="stateAlwaysHidden"
in my Manifest for the particular activity, but this doesn't work for me because as soon as the user clicks on the EditText the keyboard appears again.
I've tried doing the same programmatically like so
activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
but that doesn't work either. Keyboard appears when the user clicks on the EditText.
The only thing that worked was setting InputType to null for the EditText like so:
EditText.setInputType(InputType.TYPE_NULL);
but I cannot use this because it will allow users who have a keyboard attached to their device to input letters and other symbols in the EditText field, while I want everyone to specifically use only the keypad to enter data in the field.
I should also mention that I am currently testing my app under android 2.1, but I would like my solution to work across all versions. Any help would be appreciated. Thanks in advance.
Just thought it might be possible to extend EditText and handle the access to the softkeyboard through there and came across this question which has a very elegant solution to my problem.
Just followed the steps and this handled the softkeyboard perfectly for me. Hope it helps others that come across this issue.
In Whichever Edittext you need to disable the soft keyboard, add attribute in xml of that edit text.
<EditText android:id=".."
..
android:focusable="false" />
It will stop the execution of soft keyboard.
Use the android:windowSoftInputMode="stateHidden" in your activity in manifest file. This will work. Don't use the android:focusable="false" for EditText unless if you are not willing to input the text. If you want to give input then remove that property for the edittext in the layout file.
You can try this. It is working for me:
getWindow().setFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
If you are using for example ViewGroup it allows you to block the soft keyboard using this method:
view.setDescendantFocusability(view.FOCUS_BLOCK_DESCENDANTS);
Thanks to this the view will get focus before any of its descendants.
you can use This Code:
<EditText
.
.
android:enabled="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:inputType="numberPassword" />