Android weird display behaviour with soft keyboard - android

I click a button and launch an activity with a soft keyboard:
When I click on the Cancel button, it calls finish() to exit to the first page. Then when I launch the activity again i get this:
The layout with the buttons is now hidden behind the keyboard.
In another scenario if i do it this way:
Launch activity.
Click back button to dismiss keyboard.
Click back button to go to first page.
Launch activity.
I get picture 1. The buttons don't get hidden. Seems like I have to destroy the keyboard before calling finish().
How do I solve this problem?
Edit: Added example of what's in the Manifest
<activity
android:name=".SignUp"
android:theme="#style/DefaultTitle" />
This is in my manifest as well, I added it after reading some other posts, didn't work for me.
<uses-sdk
android:minSdkVersion="4"
android:targetSdkVersion="7" />
Ok LOL. Weird discovery. If I do this:
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(cancel.getApplicationWindowToken(), 0);
try {
Thread.sleep(100);
} catch (Exception e) {
}
finish();
it works! Not sure if this is a good workaround....

I think you are showing the SoftKeyBoard Using STATE_ALWAYS_VISIBLE Thats Why it remain visible when you comes back to the activity.
So Try to open keyboard on Button Click this way..
EditText editText = (EditText) findViewById(R.id.myEdit);
InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
// only will trigger it if no physical keyboard is open
mgr.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);
And if there are any windowSoftInputMode in Manifest,Remove them cause will not need them for above method.

Put this line in your activity tag and let me know what happen,
<activity android:windowSoftInputMode="stateVisible" . . . >
For more info look at android:windowSoftInputMode

Try using setfocus method on object of edittext

Related

how do you make it so the Android keyboard doesnt open up when the user opens up my app?

can you make it so when you open up the app the on screen keyboard wont open up untill you click on one of the editText's?
In order to hide the virtual keyboard, you can use the InputMethodManager like this (you can put it in the onCreate()method of your landing activity) :
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(myEditText.getWindowToken(), 0);
Add the following code in onCreate method of your activity:
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
It did the trick for me :)
in AndroidManifest.xml set android:configChanges="keyboardHidden"
it is up to your requirement. For suppose if you want to hide the keyboard every time the user opens your activity, then you can add
android:windowSoftInputMode="stateAlwaysHidden" in your android manifest for your activity. If you want it dynamically then you can make change whenever event to close the keyboard occurs using
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(myEditText.getWindowToken(), 0);
Use this as reference whenever you want

How to open input Keyboard on load of activity

I have an EditText in my activity class. What I want is, whenever my activity starts it automatically opens the input keyboard along with EditText. So how that can be done? Please anyone suggest it to me, if possible with example
If you want to always show soft keyboard whenever your activity is started, the simplest way is to add this piece of code in your Android Manifest file:
<activity android:name=".YourActivity"
android:windowSoftInputMode="stateAlwaysVisible" />
This will just work without you doing anything else with your code.
add this in your manifest file this will do
<activity android:windowSoftInputMode="stateVisible|adjustResize" . . . >
here is another method:-
EditText editText = (EditText) findViewById(R.id.myEdit);
InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
// only will trigger it if no physical keyboard is open
mgr.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);
set this flag in activity's onCreate() methodgetWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);

How do I remove the keyboard after I finish an activity?

I have an activity that users type inside and then click the ok button. When it is finished, the activity closes and goes back to the old activity but the soft keyboard is still on the screen! I've tried android:windowSoftInputMode="stateHidden" and
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
But it does nothing.
In OnPause of your activity, you should do the following
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(et.getWindowToken(), 0);
Where et is an instance of your EditText.

Can't get keyboard to load onCreate()

My aim is to get the keyboard to open as soon as the app is loaded. Using this code,
InputMethodManager inputMgr = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
inputMgr.toggleSoftInput(0, 0);`
on a button, I can get the keyboard to load when the button is pressed. However, when placed in the override onCreate() section, nothing happens.
Add the following line to the activity in AndroidManifest.xml
android:windowSoftInputMode="stateVisible|adjustPan"

Show soft keyboard when Activity starts when no text field is present

I want to open soft keyboard while starting an activity.
The activity contains nothing as its element. I just need to open soft keyboard on the launch.
I've tried with
<activity android:windowSoftInputMode="stateAlwaysVisible|stateVisible|adjustResize" but it didn't work.
Also tried with
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
but it didn't work as well
i'm using emulator to run the code
Thanks in advance
Have you tried
<activity
android:windowSoftInputMode="stateVisible|adjustPan">
?
HI,
you could try :
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(flags, InputMethodManager.SHOW_IMPLICIT);
This will not open the keyboard if there is a physical one available and opened.(flags can be 0 if there is nothing.)
try the below code hope it helps
<activity android:windowSoftInputMode="adjustPan">
for more information regarding this Read

Categories

Resources