Android: How to make the keyboard always visible?

In android, how do we make the device keyboard always visible in the application? The upper part displays the content that the application wants to render, and the lower part always displays the keyboard.

+29
android
02 Oct '09 at 14:03
source share
3 answers

Add android: windowSoftInputMode = "stateAlwaysVisible" for your activity in the AndroidManifest.xml file:

<activity android:name=".MainActivity" android:label="@string/app_name" android:windowSoftInputMode="stateAlwaysVisible" /> 

In my test application, this shows the keyboard when the application starts, although it is not fixed there, but can be rejected by pressing the "Back" button.

To make sure the keyboard is always visible, you may have to create your own keyboard as part of the user interface of your application. Below is a tutorial showing how to do this with KeyboardView: http://www.fampennings.nl/maarten/android/09keyboard/index.htm

+38
Oct 02 '09 at 14:51
source share

Your layout should have an EditText , and this requires the size of the EditText base class. then override onKeyPreIme() and return True . Now your keyboard will always be visible and cannot be canceled by the back button.

Attention Due to the fact that your onKeyPreIme() method returns true , you cannot exit your application using the return key.

Example:

 public class CustomEdit extends EditText { public CustomEdit(Context context, AttributeSet attrs) { super(context, attrs); // TODO Auto-generated constructor stub } @Override public boolean onKeyPreIme(int keyCode, KeyEvent event) { // TODO Auto-generated method stub Log.e("Log", "onKeyPreIme"); return true; //return super.onKeyPreIme(keyCode, event); } } 

onKeyPreIme () - Android developer

+10
03 Sep
source share

I found a way that works for me to keep the soft keyboard visible after editing in my myEditText field of the myEditText class. The trick is to override the onEditorAction method onEditorAction that it returns true

  myEditText.setOnEditorActionListener(new OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { return true; } }); 

or else onEditorAction return true only after pressing the "Finish" key ( IME_ACTION_DONE ), otherwise false

  myEditText.setOnEditorActionListener(new OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if(actionId==EditorInfo.IME_ACTION_DONE){ Log.i(LOG_TAG, "IME_ACTION_DONE"); return true; } return false; } }); 

(see also this answer on the onEditorAction method)

Adding android:windowSoftInputMode="stateAlwaysVisible to the manifest file helped to display a soft keyboard at the start of the activity, but this did not stop it from disappearing again whenever after clicking the" Finish "button it was pressed after editing.

0
Feb 18 '14 at 18:26
source share



All Articles