Ste*_*lla 6 android android-layout android-softkeyboard android-edittext android-fragments
我加入EditText了Fragment,但EditText即使点击我也没有显示键盘EditText.
这是我的代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white">
<EditText
android:id="@+id/setting_nickname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="8"
android:gravity="right"
android:hint="Samantha"
android:textColorHint="@color/nav_selected"
android:textSize="14dp"
android:textColor="@color/nav_selected"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" >
</EditText>
<EditText
android:id="@+id/setting_country"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="8"
android:gravity="right"
android:hint="Samantha"
android:textColorHint="@color/nav_selected"
android:textSize="14dp"
android:textColor="@color/nav_selected"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" >
</EditText>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
我试着听听 EditText
final InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
edit_nickname.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
imm.showSoftInput(edit_nickname, 0);
//edit_nickname.requestFocus(); --> fail
//imm.showSoftInput(edit_nickname, InputMethodManager.SHOW_IMPLICIT); --> fail
//imm.showSoftInput(edit_nickname, InputMethodManager.SHOW_FORCED); --> fail
}
});
Run Code Online (Sandbox Code Playgroud)
这段代码不能......
final InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
Run Code Online (Sandbox Code Playgroud)
此外,我尝试添加LinearLayout到focusableInTouchMode和focusable,但失败了.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="10dp"
android:padding="10dp"
android:background="@color/black_transparent"
android:focusableInTouchMode="true"
android:focusable="true">
<EditText .../>
<EditText .../>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
如果我使用<requestFocus />比键盘显示但它只适用于其中一个EditText.我能怎么做?为什么不显示键盘?
尝试在单独的线程或处理程序中执行以下代码。
editText.postDelayed(new Runnable() {
@Override
public void run() {
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
if(imm != null)
imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);
}
},1000);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1397 次 |
| 最近记录: |