I want to include a toolbar in my settings page and followed this instruction: https://stackoverflow.com/a/27455330/2977288 (first part)
For some reason, the toolbar overlaps the content:
I also tried to make the text color white: https://stackoverflow.com/a/26555178/2977288
But as you can see in the screenshot, the color remains black.
Here is the code I'm using:
settings_toolbar.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:minHeight="?attr/actionBarSize"
android:background="@color/colorPrimary"
app:navigationIcon="?attr/homeAsUpIndicator"
app:title="@string/action_settings"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
SettingsActivity.java
public class SettingsActivity extends PreferenceActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Display the fragment as the main content.
getFragmentManager().beginTransaction()
.replace(android.R.id.content, new SettingsFragment())
.commit();
}
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
LinearLayout root = (LinearLayout)findViewById(android.R.id.list).getParent().getParent().getParent();
Toolbar bar = (Toolbar) LayoutInflater.from(this).inflate(R.layout.settings_toolbar, root, false);
root.addView(bar, 0); // insert at top
bar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
}
}
preferences.xml
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
>
<PreferenceCategory android:title="@string/pref_main">
<CheckBoxPreference
android:key="vibration"
android:title="@string/pref_vibration"
android:summary="@string/pref_summary_vibration"
android:defaultValue="true" />
<Preference
android:key="show_wizard"
android:title="@string/pref_wizard"
android:summary="@string/pref_summary_wizard">
<intent
android:action="android.intent.action.VIEW"
android:targetPackage="de.tum.dstrctrl"
android:targetClass="de.tum.dstrctrl.activities.WizardActivity" />
</Preference>
</PreferenceCategory>
</PreferenceScreen>
Does anybody has an idea about one of the two issues (or both)?