当键盘出现时,Android cutom工具栏导致ListView无法滚动浏览所有元素

时间:2019-07-13 22:01:51

标签: android android-linearlayout android-toolbar

我已经实现了自己的工具栏(“顶部应用程序栏”)以添加一些其他功能。该工具栏的工作原理非常好,就像android提供的默认标题(set_coef_names <- function(x) { names(x$coefficients) <- c("Constant", "Length", "Width", "Length * Width") return(x) } for (i in 1:2) { assign(paste("model_", i, sep = ""), set_coef_names(get(paste("model_", i, sep = "")))) } )仅带有标题一样。但是,工具栏会隐藏状态栏,更重要的是,当android键盘出现时,我的ActionBar不会滚动显示所有元素,而停在它上面的元素则显示了一半。

我希望具有与默认ListView相同的功能,并且上面有我想要的物品。

主要布局:

ActionBar

菜单(顶部应用栏):

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    android:orientation="vertical"
    tools:context=".MessageActivity">

    <androidx.appcompat.widget.Toolbar
        android:orientation="vertical"
        android:id="@+id/message_toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="@color/colorPrimary"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
        app:layout_scrollFlags="scroll|enterAlways"
        app:contentScrim="?attr/colorPrimary"
        />

    <ListView
        android:layout_width="match_parent"
        android:id="@+id/messages_view"
        android:layout_weight="2"
        android:divider="#fff"
        android:layout_height="match_parent"
        android:smoothScrollbar="true"
        />
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#fff"
        android:orientation="horizontal">
        <EditText
            android:id="@+id/editText"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:ems="10"
            android:hint="@string/write_your_message"
            android:inputType="text"
            android:paddingHorizontal="10dp"
            android:text="" />


        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:scaleType="fitCenter"
            android:padding="20dp"
            android:layout_marginHorizontal="10dp"
            android:background="@drawable/ic_send_black_24dp"
            android:onClick="sendMessage"/>
    </LinearLayout>
</LinearLayout>

更新至问题:

问题是样式xml对于我的无操作栏有<?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"> <item android:id="@+id/settings_label" android:title="@string/title_activity_settings" /> <item android:id="@+id/convo_label" android:checked="true" app:showAsAction="ifRoom" android:title="@string/convo" /> <item android:id="@+id/returnHome" android:icon="@drawable/outline_home_24" app:showAsAction="ifRoom" android:title="@string/title_home" /> </menu> 。所以原来我有

<item name="android:windowFullscreen">true</item>

此更改使其有效:

<style name="AppTheme.NoActionBar" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="android:windowFullscreen">true</item>
</style>

1 个答案:

答案 0 :(得分:1)

在AndroidManifest.xml中的android:windowSoftInputMode="adjustResize"标签中添加属性activity。它使软键盘上推视图以使所有项目均可访问。

示例:

<application ...>
  <activity
    android:windowSoftInputMode="adjustResize"
    android:name=".MainActivity" />
</application>

请参阅:windowSoftInputMode