如何根据PreferenceFragment的工具栏颜色设置状态栏颜色?
我希望我的状态栏是绿色的。我的应用程序也支持较早的设备。
提前致谢。
我的问题截图:
settings.xml
我的问题截图:
![http://i.imgur.com/013x4Mo.png](https://istack.dev59.com/2G3Ux.webp)
<?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>
PreferencesActivity.java
public class PreferencesActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.settings);
getFragmentManager().beginTransaction()
.replace(R.id.content_frame, new SettingsPreference())
.commit();
}
public static class SettingsPreference extends PreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
// applyTheme();
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.pref_settings);
android.support.v7.widget.Toolbar toolbar = (android.support.v7.widget.Toolbar) getActivity().findViewById(R.id.toolbar);
((ActionBarActivity)getActivity()).setSupportActionBar(toolbar);
}
}