LoginSignup
4
5

More than 5 years have passed since last update.

Activity起動時にソフトウェアキーボードを出す

Posted at

onCreateでgetWindow().setSoftInputModeを呼び出してSoftInputModeの設定をすると
フォーカスが当たっている場合に、ソフトウェアキーボードが表示される。
起動時にフォーカスを当てるために、対象のEditTextにrequestFocusを追記する。

package sample.softwarekeyboard;

import android.app.Activity;
import android.os.Bundle;
import android.view.WindowManager;

public class SoftwareKeyboardActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        this.getWindow().setSoftInputMode(
                WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
    }
}
<EditText
    android:id="@+id/edit_text"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <requestFocus />
</EditText>
4
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
5