Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Soft keyboard does not show when Activity starts

I have added android:windowSoftInputMode="stateAlwaysVisible" to my Activity in AndroidManifest.xml and here's my layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <EditText android:id="@+id/EditText01" android:layout_width="wrap_content"
        android:layout_height="wrap_content"></EditText>
    <EditText android:id="@+id/EditText02" android:layout_width="wrap_content"
        android:layout_height="wrap_content"></EditText>
    <Button android:id="@+id/Button01" android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:text="Send"></Button>
</LinearLayout>

alt text http://img227.imageshack.us/img227/2006/18021414.png

When the Activity starts, the EditText is focused, but soft keyboard isn't displayed. If I click on the EditText, then I see the soft keyboard. Do I need to set aditional parameters to display soft keyboard when my Activity starts?

Thanks

like image 688
Sarp Centel Avatar asked Apr 26 '10 10:04

Sarp Centel


People also ask

How check soft keyboard is visible or not in Android?

By default, the soft keyboard may not appear on the emulator. If you want to test with the soft keyboard, be sure to open up the Android Virtual Device Manager ( Tools => Android => AVD Manager ) and uncheck "Enable Keyboard Input" for your emulator.

How do I make my keyboard always visible?

You must have an EditText in your layout and that need to extent EditText base class. then Override onKeyPreIme() method, and return True. Now your keyboard will be always visible and can't be dismissed by Back key.

How do I know if my keyboard is active?

Android provides no direct way to determine if the keyboard is open, so we have to get a little creative. The View class has a handy method called getWindowVisibleDisplayFrame from which we can retrieve a rectangle which contains the portion of the view visible to the user.


2 Answers

solution 1 :

write following code inside onCreate() method of activity

InputMethodManager imm = (InputMethodManager)
    SearchActivity.this.getSystemService(Context.INPUT_METHOD_SERVICE);

if (imm != null){
    imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,0);
}

solution 2 :

create following method and call from onCreate()

private void showVirturalKeyboard(){
    Timer timer = new Timer();
    timer.schedule(new TimerTask() {
         @Override
         public void run() {
              InputMethodManager m = (InputMethodManager) SearchActivity.this.getSystemService(Context.INPUT_METHOD_SERVICE);

              if(m != null){
                // m.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
                m.toggleSoftInput(0, InputMethodManager.SHOW_IMPLICIT);
              } 
         }

    }, 100);         
}
like image 76
rakeshsoni Avatar answered Nov 05 '22 13:11

rakeshsoni


Try adding this to the activities onCreate() method

this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); 
like image 37
Donal Rafferty Avatar answered Nov 05 '22 13:11

Donal Rafferty