[英]Soft Keyboard doesn't pop up automatically
Layout is declared like this. 这样声明布局。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.guna.testapplication.MainActivity">
<EditText
android:hint="@string/action_settings"
android:inputType="text"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<requestFocus />
</EditText>
</RelativeLayout>
Activity declared like this. 活动声明如下。
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
And Activity
added in manifest as like this. 像这样在清单中添加了
Activity
。
<activity
android:name=".MainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
When I run this app I am getting following output. 当我运行此应用程序时,我得到以下输出。
I don't know why soft keyboard doesn't pop up automatically. 我不知道为什么软键盘不会自动弹出。
To force the soft keyboard to appear, you can use 要强制显示软键盘,可以使用
EditText yourEditText= (EditText) findViewById(R.id.yourEditText);
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(yourEditText, InputMethodManager.SHOW_IMPLICIT);
Add this to your edittext and try 将此添加到您的edittext,然后尝试
android:focusable="true"
android:focusableInTouchMode="true"
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:windowSoftInputMode="adjustPan|adjustNothing">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
or in your activity
EditText actionSettings= (EditText) findViewById(R.id.action_settings);
InputMethodManager imm = (InputMethodManager)
getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(actionSettings, InputMethodManager.SHOW_IMPLICIT);
将此行添加到清单活动中。
android:windowSoftInputMode="stateAlwaysVisible"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.