Skip to content Skip to sidebar Skip to footer

Android Studio - Always Show Keyboard?

I'm attempting to create a simple text adventure type game as a project to help me learn stuff. For this I need the keyboard to always be visible and focused on the only Edit Text

Solution 1:

Below is the sample code which you could re-use,

In the AndroidManifest.xml use this..

android:windowSoftInputMode="stateAlwaysVisible"

like below

<activityandroid:name=".MainActivity"android:windowSoftInputMode="stateAlwaysVisible"><intent-filter><actionandroid:name="android.intent.action.MAIN" /><categoryandroid:name="android.intent.category.LAUNCHER" /></intent-filter></activity>

In your layout you can use

    <EditText
        android:id="@+id/editText"
        android:singleLine="true"
        android:imeOptions="actionDone"
        ... 
     />

In OnCreate() method of your activity, you could implement something like this...

finalEditTexteditText= ((EditText) findViewById(R.id.editText));
        editText.setOnEditorActionListener(newEditText.OnEditorActionListener(){
            @OverridepublicbooleanonEditorAction(TextView v, int actionId, KeyEvent event) {
                    Stringvalue= editText.getText().toString();
                    //TODO .. write your respective logic to add data to your textView

                    editText.setText(""); // clear the text in your editTextreturntrue;

            }
        });

Post a Comment for "Android Studio - Always Show Keyboard?"