【问题标题】:Why is the Action bar covering my listView?为什么 Action bar 覆盖了我的 listView?
【发布时间】:2018-01-23 13:38:33
【问题描述】:

我正在按照https://developer.android.com/training/appbar/index.html 中概述的步骤向我的活动添加操作栏。

但是,按照描述添加它涵盖了我的 ListView。该列表有 2 个条目。在我尝试添加操作栏之前,它是这样的:

在这里,我按照步骤调整了清单和我的活动布局:

     <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        android:elevation="4dp"
        android:popupTheme="@style/ThemeOverlay.AppCompat.Light"
        android:theme="@style/ThemeOverlay.AppCompat.ActionBar" />

    <ListView
        android:id="@+id/listView"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</RelativeLayout>

现在看起来像这样:

我尝试使用 AppBarLayout 对象包装工具栏,如 https://stackoverflow.com/questions/35845629/actionbar-covering-my-activity 所示,但这不起作用。

如何将 ActionBar 添加到我的活动中而不覆盖 ListView。我想在活动的操作栏(不是溢出菜单)中添加几个按钮,以便提供添加到列表的选项。

【问题讨论】:

    标签: android android-actionbar


    【解决方案1】:
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            android:elevation="4dp"
            android:popupTheme="@style/ThemeOverlay.AppCompat.Light"
            android:theme="@style/ThemeOverlay.AppCompat.ActionBar" />
    
        <ListView
            android:id="@+id/listView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@+id/toolbar" />
    
    
    </RelativeLayout>
    

    【讨论】:

      【解决方案2】:

      我认为您忘记在列表视图中添加 android:layout_below="@+id/toolbar" 因为您的布局是相对的。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-09-22
        • 1970-01-01
        • 2023-03-27
        • 2021-04-13
        相关资源
        最近更新 更多