I seem to have a problem implementing a theme onto a PreferenceActivity when i am using an XML reference to refer to said theme.
I have 3 style.xml´s
?attr/inst_theme
inst_theme
as the theme name.
This works perfect in API 16
But....PreferenceActivity class code:
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
Toolbar bar;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
LinearLayout root = (LinearLayout) findViewById(android.R.id.list).getParent().getParent().getParent();
bar = (Toolbar) LayoutInflater.from(this).inflate(R.layout.pref_toolbar, root, false);
root.addView(bar, 0);
} else {
ViewGroup root = (ViewGroup) findViewById(android.R.id.content);
ListView content = (ListView) root.getChildAt(0);
root.removeAllViews();
bar = (Toolbar) LayoutInflater.from(this).inflate(R.layout.pref_toolbar, root, false);
int height;
TypedValue tv = new TypedValue();
if (getTheme().resolveAttribute(R.attr.actionBarSize, tv, true)) {
height = TypedValue.complexToDimensionPixelSize(tv.data, getResources().getDisplayMetrics());
}else{
height = bar.getHeight();
}
content.setPadding(0, height, 0, 0);
root.addView(content);
root.addView(bar);
}
bar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
}
inst_theme (same as v16)
<style name="inst_theme" parent="AppBaseTheme">
<item name="android:background">@drawable/jrw_back_material_empty</item>
<item name="android:textColorTertiary">@color/pref_summary</item>
</style>
inst_theme (v21)
<style name="inst_theme" parent="AppBaseTheme">
<item name="android:windowBackground">@color/grijswit</item>
<item name="android:colorPrimary">@color/jumbo_main_2</item>
<item name="android:colorPrimaryDark">@color/antraciet</item>
<item name="android:textColorPrimary">@color/pref_name</item>
<item name="android:textColorSecondary">@color/pref_name</item>
<item name="android:textColorTertiary">@color/pref_name</item>
<item name="android:textColor">@color/pref_summary</item>
<item name="android:preferenceCategoryStyle">@style/pref_style</item>
</style>
<style name="pref_style" parent="AppBaseTheme">
<item name="android:layout">@layout/pref_cat_style</item>
</style>
pref_cat_style.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/title"
android:layout_width="match_parent"
android:layout_height="48dp"
android:gravity="center_vertical"
android:textColor="@color/jumbo_main_2"
android:textStyle="bold"
style="@style/TextAppearance.AppCompat.Body1"/>
AppBaseTheme:
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
</style>
I hope you can maybe help me solve this problem, i just don't see what i am doing wrong, all the other styles are being used just fine by every API.
Thank you in advance :)
Fixed it!
i just renamed all the styles to inst_theme
and referenced them with just @style/inst_theme
Moral of the story: Think before you post