【问题标题】:keyboard covers half of the edit text Android键盘覆盖了一半的编辑文本 Android
【发布时间】:2017-09-05 11:41:33
【问题描述】:

我正在开发一个应用程序,我发现键盘隐藏 EditText 字段的问题。经过研究,我通过在清单文件中添加这行代码找到了解决方案。

android:windowSoftInputMode="adjustPan"

但现在我的编辑文本看起来像

表情图标、编辑文本和发送文本视图采用线性布局。如何在键盘上方显示整个线性布局?

【问题讨论】:

  • 希望 Answer 对您有所帮助 ....

标签: android android-edittext keyboard


【解决方案1】:

我对@9​​87654321@ 有完全相同的问题,所以我改用它..

android:windowSoftInputMode="adjustResize"

我希望你的根布局是RelativeLayout

更新

尝试这样设置。

chat_ui.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/chat_layout"
    android:background="@color/white">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/applayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="@color/white"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light">

            <TextView
                android:id="@+id/txtTitle"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginRight="40dp"
                android:gravity="center_horizontal"
                android:text="Francis"
                android:textColor="@color/page_background"
                android:textSize="10pt" />

        </android.support.v7.widget.Toolbar>

    </android.support.design.widget.AppBarLayout>

    <ListView
        android:layout_below="@id/applayout"
        android:id="@+id/chat_list_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/bottomlayout"
        android:layout_marginBottom="4dp"
        android:clipToPadding="false"
        android:divider="@drawable/chat_divider"
        android:paddingBottom="4dp"
        android:paddingTop="8dp"
        android:scrollbarStyle="outsideOverlay"
        android:stackFromBottom="false"
        android:transcriptMode="normal" />

    <LinearLayout
        android:id="@+id/bottomlayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:orientation="horizontal">

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:layout_weight="1"
            android:background="@drawable/input"
            android:minHeight="50dp"
            android:orientation="horizontal"
            android:paddingBottom="15dp"
            android:paddingLeft="12dp"
            android:paddingRight="20dp">

            <!--  <ImageView
                  android:id="@+id/emojiButton"
                  android:layout_width="24dp"
                  android:layout_height="24dp"
                  android:layout_gravity="bottom"
                  android:src="@drawable/input_emoji" />-->

            <EditText
                android:id="@+id/chat_edit_text1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="bottom"
                android:layout_marginLeft="12dp"
                android:background="@null"
                android:hint="@string/type_message"
                android:inputType="textMultiLine"
                android:singleLine="false"
                android:textColorHint="#c4c0bd"
                android:textSize="18sp" />

        </LinearLayout>

        <ImageButton
            android:id="@+id/enter_chat1"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:layout_gravity="bottom"
            android:background="@drawable/input_circle_normal"
            app:srcCompat="@drawable/ic_send" />

    </LinearLayout>

</RelativeLayout>

在清单中

<activity
     android:name=".activities.ChatActivity"
     android:windowSoftInputMode="stateHidden|adjustResize"
     android:screenOrientation="portrait"
     android:theme="@style/MyMaterialTheme2" />

【讨论】:

  • 试过了,没用:(它完全覆盖了我的editText
  • 检查我的更新.. 我的聊天应用程序的工作代码,它在我的 moto-g4 plus 和牛轧糖版本中运行良好
  • 对我不起作用 :( 感谢您提供更新的答案
【解决方案2】:

在 Manifest 中设置 android:softInputMode 属性为 adjustResize 并将布局(不是列表项布局)放入 ScrollView。

【讨论】:

  • 对不起,我不明白最后一部分“将布局(不是列表项布局)放入 ScrollView。”
  • 如果你用过listview,我的意思是不要把scrollview放到listview的布局上。你可以忽略这一点。请将滚动视图放置在编辑文本框、发送按钮等所有布局的位置。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-01-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-03-19
相关资源
最近更新 更多