我使用两个EditText'a,第一个作为标题,第二个作为注释。我设置了按钮,通过单击清除两个编辑的焦点。如果文本很小并且在可见范围内,则按预期删除技巧。如果插入长文本,或移动到新行直到滚动,焦点不再移除,这种行为的原因可能是什么?
标记代码:
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".AddNoteActivity"
tools:showIn="@layout/activity_add_note">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="vertical"
android:paddingLeft="16dp"
android:paddingRight="16dp">
<EditText
android:id="@+id/et_add_chapter_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@null"
android:hint="@string/chapter_title"
android:imeOptions="flagNavigateNext"
android:inputType="textShortMessage"
android:maxLength="100"
android:paddingBottom="5dp"
android:paddingTop="5dp"
android:textStyle="bold" />
<View
android:layout_width="match_parent"
android:layout_height="0.6dp"
android:background="@color/main" />
<EditText
android:id="@+id/et_add_chapter_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@null"
android:gravity="start"
android:hint="@string/chapter_content"
android:inputType="textMultiLine|textLongMessage"
android:minHeight="200dp"
android:paddingBottom="5dp"
android:paddingTop="5dp">
<requestFocus />
</EditText>
</LinearLayout>
在活动中:
etAddChapterTitle.clearFocus();
etAddChapterContent.clearFocus();
找到了原因。第二个
EditText应该有一个高度match_parent,但在你添加一个之前ScrollView它不会变成。match_parentScrollViewandroid:fillViewport="true"