Search code examples
androidkeyboardandroid-edittext

How to show virtual keyboard on start Activity?


I want to show virtual keyboard as soon as activity is started, but unable to achieve it.. I am trying to set android:windowSoftInputMode="stateAlwaysVisible" in manifest but it's not working for me..

It shouldn't be dismissed once i back press.

Is it possible to display virtual keyboard on our own layout???

Here is the part of manifest file

 <application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:windowSoftInputMode="stateAlwaysVisible" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".FriendsList"
        android:screenOrientation="portrait" />
    <activity android:name=".Places" />
</application>

Solution

  • Try this below code its working

    final TextView txtPassword = (TextView) findViewById(R.id.txtpassword);
           
           txtPassword.postDelayed(new Runnable() {
            @Override
            public void run() {
                InputMethodManager keyboard = (InputMethodManager)
                getSystemService(Context.INPUT_METHOD_SERVICE);
                keyboard.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); 
            }
        },200);