在我的布局中,我使用了两个Spinner
和Editext
,当我点击Edittext
软键盘外没有隐藏,Edittext
焦点也没有改变..
我的布局文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/ic_bgfind"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="vertical"
android:paddingTop="?android:attr/actionBarSize" >
<TextView
android:id="@+id/drivernametext"
android:layout_width="match_parent"
android:layout_height="@dimen/ui_height"
android:layout_marginBottom="6dp"
android:layout_marginLeft="@dimen/ui_margin"
android:layout_marginRight="@dimen/ui_margin"
android:layout_marginTop="@dimen/ui_margin"
android:gravity="center_vertical"
android:text="@string/drivernametext"
android:textColor="@color/splashscreen"
android:textSize="20sp" />
<Spinner
android:id="@+id/driverSpinner"
android:layout_width="match_parent"
android:layout_height="@dimen/ui_height"
android:layout_marginBottom="@dimen/ui_margin_bottom"
android:layout_marginLeft="@dimen/ui_margin"
android:layout_marginRight="@dimen/ui_margin"
android:background="@drawable/dropdownbtn" />
<TextView
android:id="@+id/carRegNumber"
android:layout_width="match_parent"
android:layout_height="@dimen/ui_height"
android:layout_marginBottom="6dp"
android:layout_marginLeft="@dimen/ui_margin"
android:layout_marginRight="@dimen/ui_margin"
android:gravity="center_vertical"
android:text="@string/carRegNumber"
android:textColor="@color/splashscreen"
android:textSize="20sp" />
<EditText
android:id="@+id/carRegNumberedit"
android:layout_width="match_parent"
android:layout_height="@dimen/ui_height"
android:layout_marginBottom="@dimen/ui_margin_bottom"
android:layout_marginLeft="@dimen/ui_margin"
android:layout_marginRight="@dimen/ui_margin"
android:cursorVisible="false"
android:hint="@string/carRegNumber"
android:inputType="text"
android:textColor="@color/brandcolor"
android:textColorHint="@color/edit_hint"
android:textSize="16sp" />
<TextView
android:id="@+id/inglottext"
android:layout_width="match_parent"
android:layout_height="@dimen/ui_height"
android:layout_marginBottom="6dp"
android:layout_marginLeft="@dimen/ui_margin"
android:layout_marginRight="@dimen/ui_margin"
android:gravity="center_vertical"
android:text="@string/inglottext"
android:textColor="@color/splashscreen"
android:textSize="20sp" />
<Spinner
android:id="@+id/inglotspinner"
android:layout_width="match_parent"
android:layout_height="@dimen/ui_height"
android:layout_marginLeft="@dimen/ui_margin"
android:layout_marginRight="@dimen/ui_margin"
android:background="@drawable/dropdownbtn" />
<Button
android:id="@+id/Done"
android:layout_width="match_parent"
android:layout_height="@dimen/ui_height"
android:layout_margin="@dimen/ui_margin"
android:background="@drawable/button_shape"
android:text="@string/Done"
android:textColor="@android:color/white"
android:textSize="20sp" />
</LinearLayout>
以编程方式我尝试了
final EditText carRegEdit = (EditText) findViewById(R.id.carRegNumberedit);
carRegEdit.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (!hasFocus) {
carRegEdit.clearFocus();
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(carRegEdit.getWindowToken(), 0);
}
}
});
在Activity
声明中我也试过,仍然软键盘没有隐藏。
如何隐藏它?
答案 0 :(得分:0)
如果打开,则假设处理根布局的“单击事件”以隐藏键盘。 当点击任何其他地方时,键盘将隐藏。