Android 工具栏 PreferenceActivity

Android toolbar PreferenceActivity

我按照不同的示例将工具栏插入到我的 PreferenceActivity 中。我最终找到了一个结论,但是 FrameLayout 与 Toolbar 重叠,如图所示。 这是 XML 文件。

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
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="wrap_content"
    android:background="?attr/colorPrimary"
    app:theme="@style/ToolbarColoredBackArrow"
    app:popupTheme="@style/MyDarkToolbarStyle"/>

<FrameLayout
    android:id="@+id/content_frame"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="false"
    android:layout_below="@+id/toolbar" />
</RelativeLayout>

嗯,你的布局是这么说的。 RelativeLayout 需要被告知工具栏位于框架布局之上,或者框架布局被告知位于工具栏下方。

所以要么将其添加到框架布局中:

android:layout_below="@id/toolbar"

或者工具栏中的这个:

android:layout_above="@id/content_frame"