简体   繁体   中英

Layout issues when adding toolbar to preference fragment

I try to built a preference screen with a toolbar, but I got some issues:

在此处输入图片说明

  • The status bar is white. I want it to look like my main screen (same theme). Somehow it does not apply the color
  • The toolbar overlays the content. I tried aa layout_marginTop on the list view, but it does not change anything.

Here is the code of my activity_settings.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="@color/colorPrimary"
        app:navigationIcon="?attr/homeAsUpIndicator"
        app:title="@string/action_settings"
        android:theme="@style/ThemeOverlay.AppCompat.Dark" />

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

</LinearLayout>

This is the AndroidManifest entry:

<activity
    android:name=".activities.SettingsActivity"
    android:label="@string/activity_settings"
    android:theme="@style/AppTheme.NoActionBar" />

Can anybody help me?

Add android:layout_marginTop="?attr/actionBarSize" to your ListView in the xml.

Replace fill_parent with match_parent it's deprecated. Remove android:layout_below="@+id/toolbar" it's not working in LinearLayout

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM