Android 子代clearFocus之前的布局可聚焦未按预期工作
我有一个表单布局看起来像Android 子代clearFocus之前的布局可聚焦未按预期工作,android,android-layout,layout,focus,Android,Android Layout,Layout,Focus,我有一个表单布局看起来像 <ScrollView 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"> <LinearLayout
<ScrollView 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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/small"
android:layout_marginEnd="@dimen/small"
android:layout_marginStart="@dimen/small"
android:layout_marginTop="@dimen/small">
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/small"
android:layout_marginEnd="@dimen/small"
android:layout_marginStart="@dimen/small">
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/small"
android:layout_marginEnd="@dimen/small"
android:layout_marginStart="@dimen/small">
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionDone"
android:inputType="textPassword" />
</android.support.design.widget.TextInputLayout>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/small" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/small"
android:layout_marginStart="@dimen/small"
android:layout_marginTop="@dimen/small" />
<Button
style="@style/Button.Small"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/small" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/small"
android:layout_marginEnd="@dimen/small"
android:layout_marginStart="@dimen/small">
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionDone"
android:inputType="text" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/small"
android:layout_marginEnd="@dimen/small"
android:layout_marginStart="@dimen/small">
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionDone"
android:inputType="text" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
</FrameLayout>
</LinearLayout>
但焦点并不是每次都是线性布局。焦点由第一个可见的EditText获得(头文本视图可见时例外,焦点由LinearLayout获得)
我希望线性布局始终能够获得焦点,因为它的聚焦性在之前
单击AcionOne时也是如此,我希望焦点从当前的EditText中移除,所以我实现了
if (actionId == EditorInfo.IME_ACTION_DONE) {
WindowsHelper.hideKeyboard(context, view);
view.clearFocus();
}
但焦点还是通过第一个可见文本获得的
有人知道我做错了什么吗?在你的渐变中添加下面的lib 编译'com.yinglan.keyboard:hidekeyboard:0.0.2' 在onCreate方法中添加以下代码 HideUtil.init(本)
并将焦点设置为您的父视图的真实值这只是隐藏键盘,而不是清除焦点,这是主要问题。您的意思是,您不想在打开Activity时获得焦点吗?不,我希望当用户触摸外部时,焦点从EditText中移除(而不是通过其他EditText获得)然后将焦点设置为您的父视图的真,并使用上面的库隐藏键盘。这不是问题所在。我想了解为什么我的代码不起作用。因为父代有android:genderantfocusability=“beforestandersons”,我希望它能成为焦点,但事实并非如此。
if (actionId == EditorInfo.IME_ACTION_DONE) {
WindowsHelper.hideKeyboard(context, view);
view.clearFocus();
}