我正在尝试使用软键盘,以便用户可以输入他的信息以在我的 Android 应用程序上创建一个新帐户。问题是我的一些 TextEdits 总是在屏幕外流动,用户看不到他实际输入的内容。屏幕看起来是这样的:
此屏幕是使用以下 xml 代码构建的:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:orientation="vertical"
android:layout_height="fill_parent">
<com.markupartist.android.widget.ActionBar
android:id="@+id/actionbar"
style="@style/ActionBar"/>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1.0">
<LinearLayout
android:layout_gravity="bottom"
android:paddingTop="15dip"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<EditText android:id="@+id/txtPhoneNumber"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dip"
android:layout_marginRight="15dip"
android:nextFocusUp="@+id/LoginButton"
android:nextFocusDown="@+id/txtPassword"
android:hint="Phone Number"
android:inputType="number"
android:singleLine="true" />
<EditText android:id="@+id/txtPassword"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dip"
android:layout_marginLeft="15dip"
android:layout_marginRight="15dip"
android:hint="Password"
android:inputType="textPassword"
android:singleLine="true"
android:nextFocusDown="@+id/txtName"/>
<EditText android:id="@+id/txtName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dip"
android:layout_marginLeft="15dip"
android:layout_marginRight="15dip"
android:hint="Name"
android:singleLine="true"
android:nextFocusDown="@+id/txtPin" />
<EditText android:id="@+id/txtPin"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dip"
android:layout_marginLeft="15dip"
android:layout_marginRight="15dip"
android:hint="Pin"
android:inputType="number"
android:singleLine="true" />
</LinearLayout>
</ScrollView>
<LinearLayout android:id="@+id/buttonsLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dip"
android:layout_marginLeft="15dip"
android:layout_marginRight="15dip" >
<Button android:id="@+id/btnLogin"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:text="@string/btnLogin"
android:onClick="onRegisterClick" />
</LinearLayout>
在我的 AndroidManifest.xml 中,我以这种方式定义了我的 Activity:
<activity android:name=".activity.NewAccountActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden|adjustResize" />
我尝试了布局和 windowSoftInputMode 的不同组合,但我始终无法获得正在更改为在屏幕上可见的 TextEdit。我在这里遗漏了什么吗?
感谢任何回复
最佳答案
在您的 AndroidManifest.xml 中,将此行添加到您的 Activity 标签中。
android:windowSoftInputMode="adjustPan"
像这样
<activity android:name=".activity.NewAccountActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden|adjustResize|adjustPan"/>
希望它有用。
关于Android:软键盘将 TextEdit 移出屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7161182/