触摸编辑文本时不显示键盘
keyboard isn't showing up when edit text is touched
我正在 genymotion 上测试我的应用程序。我希望在触摸编辑文本时显示键盘,请帮助我。 this is the screen shot of my app
这里是 xml
<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"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#5a5ab5"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity"
android:clickable="false">
<com.github.florent37.materialtextfield.MaterialTextField
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_below="@+id/view"
app:mtf_image="@drawable/phon"
android:id="@+id/view3">
<EditText
android:layout_width="wrap_content"
android:layout_height="40dp"
android:id="@+id/phoneNo"
android:paddingLeft="5dp"
android:textSize="18sp"
android:inputType="phone"
android:background="@drawable/phone"
android:hint="Phone Number"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
使用这种方式它会在 EditText
是焦点时显示键盘
EditText phoneNo= (EditText) findViewById(R.id.phoneNo);
phoneNo.requestFocus();
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
在您的布局 xml 文件中将此行添加到 EditText
android:focusableInTouchMode="true"
这对我有用。
参考这个link
Display Keyboard for EditText in Emulator (GenyMotion) Android 4.3
您可以使用此方法点击编辑文本框。
private void showKeyBoard(){
((InputMethodManager)Context.getSystemService(Context.INPUT_METHOD_SERVICE)).showSoftInputFromInputMethod(editTextBox_name.getWindowToken(),0);
}
尝试在您的清单文件中添加以下代码(在您的 activity 标签内):
android:windowSoftInputMode="stateAlwaysVisible"
或
android:windowSoftInputMode="stateVisible"
希望对您有所帮助。
正如您在代码中所描述的那样,您在代码中使用了 Material Library。请阅读此库文档。
显示键盘代码已在说明中描述。
app:mtf_openKeyboardOnFocus="true"
在此处 Material Library Description 添加您的 material 观点。
我正在 genymotion 上测试我的应用程序。我希望在触摸编辑文本时显示键盘,请帮助我。 this is the screen shot of my app
这里是 xml
<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"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#5a5ab5"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity"
android:clickable="false">
<com.github.florent37.materialtextfield.MaterialTextField
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_below="@+id/view"
app:mtf_image="@drawable/phon"
android:id="@+id/view3">
<EditText
android:layout_width="wrap_content"
android:layout_height="40dp"
android:id="@+id/phoneNo"
android:paddingLeft="5dp"
android:textSize="18sp"
android:inputType="phone"
android:background="@drawable/phone"
android:hint="Phone Number"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
使用这种方式它会在 EditText
是焦点时显示键盘
EditText phoneNo= (EditText) findViewById(R.id.phoneNo);
phoneNo.requestFocus();
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
在您的布局 xml 文件中将此行添加到 EditText
android:focusableInTouchMode="true"
这对我有用。
参考这个link Display Keyboard for EditText in Emulator (GenyMotion) Android 4.3
您可以使用此方法点击编辑文本框。
private void showKeyBoard(){
((InputMethodManager)Context.getSystemService(Context.INPUT_METHOD_SERVICE)).showSoftInputFromInputMethod(editTextBox_name.getWindowToken(),0);
}
尝试在您的清单文件中添加以下代码(在您的 activity 标签内):
android:windowSoftInputMode="stateAlwaysVisible"
或
android:windowSoftInputMode="stateVisible"
希望对您有所帮助。
正如您在代码中所描述的那样,您在代码中使用了 Material Library。请阅读此库文档。 显示键盘代码已在说明中描述。
app:mtf_openKeyboardOnFocus="true"
在此处 Material Library Description 添加您的 material 观点。