Android:软键盘将 TextEdit 移出屏幕

标签 android

我正在尝试使用软键盘,以便用户可以输入他的信息以在我的 Android 应用程序上创建一个新帐户。问题是我的一些 TextEdits 总是在屏幕外流动,用户看不到他实际输入的内容。屏幕看起来是这样的:

screenshot

此屏幕是使用以下 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/

相关文章:

android - 解析 C :\Documents and Settings\<user>\. android\devices.xml 时出错

android - OnClickListener 重新分配问题 - Android

android - 从 Android 中 WindowManager 添加的 View 中捕获 onTouch 或 onClick 事件

java - Android 获取 IndexOutOfBundException

文件的 Android AES-128 加密/解密非常慢。我怎样才能提高速度

java - 无法解析符号 'FirebaseFirestore'

android - 使用 dom 解析进行嵌套 xml 解析

android - 用于 Play 商店发布的 Facebook key 哈希

java - 如何根据数据库中的值将textView向右或向左对齐

android - 在单个 Activity 架构中实现多 fragment 配置(例如主从)时,我应该如何构建布局文件?