Android 从调用的活动返回后,防止EditText获得焦点而不是ImageView
返回调用Android 从调用的活动返回后,防止EditText获得焦点而不是ImageView,android,android-edittext,focus,Android,Android Edittext,Focus,返回调用活动后,如果在调用活动之前编辑文本具有焦点且显示键盘,则屏幕滚动至该编辑文本 遵循下面的场景 活动开始。没有EditText有焦点 选择1stEditText以获得焦点并弹出键盘 当键盘位于显示屏上时,向下滚动至ImageView,然后点击它,调用另一个活动 新建活动打开并返回图像 返回时,焦点会回到原来的EditText,它只有焦点而没有显示键盘 我必须再次向下滚动到图像视图,该视图将显示图像的结果。如何防止这样的事情发生。 我希望在返回调用活动时,焦点应该正好在它停止的位置,而不是滚
活动
后,如果在调用活动
之前编辑文本
具有焦点且显示键盘,则屏幕滚动至该编辑文本
遵循下面的场景
活动开始。没有EditText
有焦点
EditText
以获得焦点并弹出键盘ImageView
,然后点击它,调用另一个活动
活动
打开并返回图像
EditText
,它只有焦点而没有显示键盘图像视图
,该视图将显示图像
的结果。如何防止这样的事情发生。
我希望在返回调用活动时,焦点应该正好在它停止的位置,而不是滚动到上一个编辑文本
我已经创建了这个场景,并在下面的XML
中验证了这个问题。我已经给了我用来测试的id。
id为的图像视图
的“结果”
是屏幕外的内容,而我用于测试的编辑文本
则是id为的“edt\U测试”
XML
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/activity_focusable"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusableInTouchMode="true"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin">
<EditText
android:id="@+id/edt_test"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Hello"
android:imeOptions="actionNext"
android:inputType="text"
android:maxLines="1" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Hello"
android:imeOptions="actionNext"
android:inputType="text"
android:maxLines="1" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Hello"
android:imeOptions="actionNext"
android:inputType="text"
android:maxLines="1" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Hello"
android:imeOptions="actionNext"
android:inputType="text"
android:maxLines="1" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Hello"
android:imeOptions="actionNext"
android:inputType="text"
android:maxLines="1" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Hello"
android:imeOptions="actionNext"
android:inputType="text"
android:maxLines="1" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Hello"
android:imeOptions="actionNext"
android:inputType="text"
android:maxLines="1" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Hello"
android:imeOptions="actionNext"
android:inputType="text"
android:maxLines="1" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Hello"
android:imeOptions="actionNext"
android:inputType="text"
android:maxLines="1" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Hello"
android:imeOptions="actionNext"
android:inputType="text"
android:maxLines="1" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Hello"
android:imeOptions="actionNext"
android:inputType="text"
android:maxLines="1" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Hello"
android:imeOptions="actionNext"
android:inputType="text"
android:maxLines="1" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Hello"
android:imeOptions="actionNext"
android:inputType="text"
android:maxLines="1" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Hello"
android:imeOptions="actionNext"
android:inputType="text"
android:maxLines="1" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Hello"
android:imeOptions="actionNext"
android:inputType="text"
android:maxLines="1" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Hello"
android:imeOptions="actionNext"
android:inputType="text"
android:maxLines="1" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Hello"
android:imeOptions="actionNext"
android:inputType="text"
android:maxLines="1" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Hello"
android:imeOptions="actionNext"
android:inputType="text"
android:maxLines="1" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Hello"
android:imeOptions="actionNext"
android:inputType="text"
android:maxLines="1" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Hello"
android:imeOptions="actionNext"
android:inputType="text"
android:maxLines="1" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Hello"
android:imeOptions="actionNext"
android:inputType="text"
android:maxLines="1" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Hello"
android:imeOptions="actionNext"
android:inputType="text"
android:maxLines="1" />
<ImageView
android:layout_width="match_parent"
android:layout_height="150dp"
android:background="#ffffff"
android:onClick="onClickGetSignature"
android:src="@drawable/powered_by_google_light" />
<ImageView
android:layout_width="match_parent"
android:layout_height="150dp"
android:background="#ffffff"
android:onClick="onClickGetSignature"
android:src="@drawable/powered_by_google_light" />
<ImageView
android:id="@+id/result"
android:layout_width="match_parent"
android:layout_height="150dp"
android:background="#ffffff"
android:onClick="onClickGetSignature"
android:src="@drawable/powered_by_google_light" />
</LinearLayout>
</ScrollView>
在线性布局中也设置android:focusable=true
,以防止EditText
获得焦点。@如果问题仍然存在,当您来自其他活动时,请在LinearLayout
上调用requestFocus()
或在线性布局中调用ImageView
@AsifPatel requestFocus()。非常感谢你。