代码之家  ›  专栏  ›  技术社区  ›  Beppe

显示键盘的控制位置

  •  0
  • Beppe  · 技术社区  · 10 年前

    作为我在android中的新手,我正在编写一个应用程序,在我的布局文件中,我有一个编辑文本和屏幕底部下面的两个按钮,如下所示:

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:layout_alignParentBottom="true"
        android:orientation="vertical"
        android:layout_gravity="bottom">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:layout_weight="1"
            android:orientation="horizontal">
            <EditText
                android:id="@+id/composeMessageBody"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:layout_weight="1"
                android:background="@android:color/white"
                android:hint="@string/message_hint"
                android:textColor="@android:color/black"
                android:textSize="18dp" />
        </LinearLayout>
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:layout_weight="1"
            android:orientation="horizontal">
            <Button
                android:id="@+id/Button1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_margin="5dp"
                android:layout_weight="1"
                android:background="@drawable/button_style_left" />
            <Button
                android:id="@+id/Button2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_margin="5dp"
                android:layout_weight="1"
                android:background="@drawable/button_style_right" />
        </LinearLayout>
    

    结果是:

    当用户点击编辑文本时,键盘会出现在绿色按钮上,还有我的操作栏和屏幕上方的部分消失或消失。这是我的问题:我如何才能拥有下图所示的状态?

    在这张图片中,发送按钮和编辑文本都在一行中,对于我来说是两行。谢谢你们。

    2 回复  |  直到 10 年前
        1
  •  1
  •   Community Mohan Dere    8 年前

    我想你需要 AndroidManifest.xml file添加此行:

      android:windowSoftInputMode="stateVisible|adjustResize">
    

    <activity> 部分

    之后,你的舱单 xml 文件看起来像这样

     ?xml version="1.0" encoding="utf-8"?>
    <manifest package="com.example.piotr.myapplication"
              xmlns:android="http://schemas.android.com/apk/res/android">
    
        <application
            android:allowBackup="true"
            android:icon="@mipmap/ic_launcher"
            android:label="@string/app_name"
            android:supportsRtl="true"
            android:theme="@style/AppTheme">
            <activity
                android:name=".MainActivity"
                android:windowSoftInputMode="stateVisible|adjustResize">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN"/>
    
                    <category android:name="android.intent.category.LAUNCHER"/>
                </intent-filter>
            </activity>
        </application>
    </manifest>
    

    你的View afet打开键盘会是这样的

    请同时检查: How to add a bottom menu to Android activity

    如果您有任何问题,请随时提问。

    希望有帮助

        2
  •  0
  •   M.ArslanKhan    10 年前
     <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:windowSoftInputMode="adjustPan"
        >
    

    将其添加到清单文件中。