java - Android 中工具栏与元素重叠

标签 java android android-studio

我正在我的应用程序中实现 ListView 。我正在尝试为 android 6.0 构建我的应用程序并选择主题“DarkActionBar”。我现在在activity_main.xml 中有此代码。

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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"
    tools:context="com.mycompany.www.mynotes.MainActivity">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" />
    </android.support.design.widget.AppBarLayout>

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

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

我刚刚在此代码中添加了一个 ListView (替换 TextView )。当我创建项目时,其余代码已经存在。

现在我正在 ListView 中随机添加一些项目。 现在的问题是, ListView 最上面的项目位于工具栏后面,如下图所示。如何修复它?我希望此 ListView 在工具栏下方启动。

enter image description here

最佳答案

您必须将 app:layout_behavior 添加到 LiveView 中:

<ListView
        android:id="@+id/android:list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

关于java - Android 中工具栏与元素重叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36970445/

相关文章:

java - getInstitutions 在 AggCatSampleApp 中返回 null

java - 如何对两个数组进行相互关联的排序?

java - 使用 Google Drive SDK 将文件保存在特定文件夹中

android - 无法解析 : multidex-instrumentation

android - 如何在Youtube Player-API中播放多个视频?

android - ClassCastException 安卓工作室

java - 无法从 Java 连接到 MySQL : NullPointerException inside MySQL driver connection logic

java - 恢复错误编码的字符(Java)

android - 如何从Android中的音频检测语音成分?

Android 和 NDK/库