I added EditTextin Fragment, but mine EditTextdoes not show the keyboard, even if I press EditText.
Here is my code
<?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>
I'm trying to get a listener 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);
}
});
And this code cannot ...
final InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
In addition, I am trying to add LinearLayoutto have focusableInTouchModeand focusable, but failed.
<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>
If I use <requestFocus />what the keyboard displays, but only applies to one of EditText. How can i do And why doesn't the keyboard appear?
source
share