Wrong Theme being applied to PreferenceActivity with xml reference

300 views Asked by At

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

  • style.xml
  • style.xml (v16)
  • style.xml (v21)
    each of these in its appropriate values directory.
    To apply the theme, i reference it in my manifest with ?attr/inst_theme
    And i ofcourse refrence inst_theme as the theme name. This works perfect in API 16 But....
    When i try out the the theme on API 21 it looks like this.
    enter image description here
    But it is supposed to look like this enter image description here i achieve this by changing the V21 inst_theme name and using this with @style/inst_theme in the manifest
    Another but...
    Meanwhile on API 16 with these settings:
    enter image description here
    This doesn't really need clarification.
    I set up my preference activity according to this Thread

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 :)

1

There are 1 answers

0
Harjan On BEST ANSWER

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