【问题标题】:Control position of displayed keyboard显示键盘的控制位置
【发布时间】:2016-01-01 22:04:32
【问题描述】:

由于我是 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>

结果如下:

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

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

【问题讨论】:

    标签: android android-layout autocompletetextview


    【解决方案1】:

    我认为你需要在你的AndroidManifest.xml 文件中添加这一行:

      android:windowSoftInputMode="stateVisible|adjustResize">
    

    &lt;activity&gt; 部分。

    之后,您的清单 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】:
     <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:windowSoftInputMode="adjustPan"
        >
    

    将此添加到您的清单文件中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-10-25
      • 1970-01-01
      • 1970-01-01
      • 2021-11-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-18
      • 1970-01-01
      相关资源
      最近更新 更多