Android PreferenceFragment:根据工具栏颜色设置状态栏

Android PreferenceFragment:根据工具栏颜色设置状态栏,android,toolbar,android-actionbaractivity,preferencefragment,Android,Toolbar,Android Actionbaractivity,Preferencefragment,如何根据PreferenceFragment的工具栏颜色设置状态栏颜色? 我想在我的状态栏中显示绿色。我的应用程序也支持棒棒糖前的设备。 提前谢谢 我的问题截图: settings.xml <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.andro

如何根据PreferenceFragment的工具栏颜色设置状态栏颜色? 我想在我的状态栏中显示绿色。我的应用程序也支持棒棒糖前的设备。 提前谢谢

我的问题截图:

settings.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
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"
tools:context="com.example.timepass.sampleapp.Settings"
android:fitsSystemWindows="true">

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?attr/colorPrimary"
    android:minHeight="?attr/actionBarSize"
    app:navigationContentDescription="@string/abc_action_bar_up_description"
    app:navigationIcon="?attr/homeAsUpIndicator"
    app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
    app:title="@string/action_settings" />
<FrameLayout
    android:id="@+id/content_frame"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/toolbar" />

</RelativeLayout>
我用这个:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        getWindow().setStatusBarColor(yourColor);

对于棒棒糖制作前的设备,请使用此

您只想更改此片段或角色应用程序中状态栏的颜色吗?@Renan Lopes Ferreira,仅此片段。没有人有此解决方案>
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        getWindow().setStatusBarColor(yourColor);