我希望在活动启动时将我的EditText
视图聚焦,因此我有以下代码:
<activity
android:name=".TestViewActivity"
android:windowSoftInputMode="stateVisible|adjustPan"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.DeviceDefault.NoActionBar.Fullscreen">
</activity>
这是一个在Button
点击后启动的第二个活动。如果没有android:windowSoftInputMode="stateVisible
,EditText
在启动时将不会获得焦点,所以我加了这个属性。我的问题是,它确实获得了焦点,但它也将上面的TextView
推了上去,即使使用了adjustPan
。这是整个活动的xml文件:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:id="@+id/typeView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:id="@+id/wordsView"
android:text="@string/hello_world"/>
</RelativeLayout>
我希望能够获得焦点并防止键盘将TextView
向上推。
<requestFocus />
在布局中请求焦点,就像这样:
- mbonness