Android - 软键盘将我的活动布局推出屏幕

ven*_*iri 25 android android-softkeyboard android-edittext

我的活动的布局如下所示.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   android:orientation="vertical">

   <FrameLayout android:id="@+id/title_bar"
      android:layout_width="fill_parent"
      android:layout_height="25dip"
      android:background="@drawable/bg_title" />

   <LinearLayout android:id="@+id/main"
      android:width="fill_parent"
      android:layout_height="fill_parent"
      android:layout_weight="1">
         <ListView android:id="@+id/android:list"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" />
         <TextView android:id="@+id/android:empty"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" />
      </FrameLayout>
   </LinearLayout>

   <LinearLayout
      android:layout_width="fill_parent"
      android:layout_height="50dip" >
      <EditText android:id="@+id/query"
         android:layout_width="fill_parent"
         android:layout_height="wrap_content" 
         android:hint="Enter some search terms"
         android:singleLine="true" 
         android:layout_weight="1" />
      <Button android:id="@+id/btn_hide"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:background="@drawable/btn_hide"
         android:layout_marginLeft="6dip" />
   </LinearLayout>
 </LinearLayout>
Run Code Online (Sandbox Code Playgroud)

因此,搜索框固定在屏幕的底部.

但是,当用户单击EditText时,软键盘会显示并将布局推出屏幕,但搜索框除外.

我刚刚开始使用Android,所以我在这里做错了什么?

Asa*_*ahi 51

尝试在Manifest中为您的活动添加以下内容:

android:windowSoftInputMode="adjustPan"
Run Code Online (Sandbox Code Playgroud)

  • 谢谢.这是我正在寻找的属性.但是,正如它的价值所在,我不得不使用"adjustResize"来使其按照我的需要工作. (6认同)
  • 嗨,我也有同样的问题.但我不能使用"adjustResize".因为我底部有tabbar.如果我使用调整大小标签栏将被推到软键盘上方.我不想发生这种情况.所以,如果有人有解决方案,请帮助我. (2认同)

Ush*_*doo 14

对于那些有兴趣,之间的区别android:windowSoftInputMode="adjustPan"android:windowSoftInputMode="adjustResize":

"adjustResize"

活动窗口的大小调整为屏幕上的软键盘腾出空间.

"adjustPan"

活动窗口的内容会自动平移,以便键盘不会阻止当前焦点.这样用户就可以看到他们正在输入的内容.这通常比调整大小更不合适,因为用户可能需要关闭软键盘以获得窗口的模糊部分并与其交互.

Android文档

引用链接


Mus*_*eel 5

@Raj如果您正在使用选项卡式应用程序,则必须添加

android:windowSoftInputMode="adjustPan"

Activity您添加选项卡的位置,这很可能是您的启动器活动.

这是我的代码中的一个片段

<activity
   android:label="@string/app_name"
   android:name=".MainActivity" android:windowSoftInputMode="adjustPan">
   <intent-filter >
     <action android:name="android.intent.action.MAIN" />
     <category android:name="android.intent.category.LAUNCHER" />
   </intent-filter>
Run Code Online (Sandbox Code Playgroud)