package android.support.v7.preference;

import android.content.Context;
import android.content.res.TypedArray;
import android.os.Build;
import android.util.AttributeSet;
import android.widget.TextView;

/**
 * PreferenceCategory fix which allows one to use multiple themes. The original
 * "preference_fallback_accent_color" override would not allow this as it is not modifiable during
 * runtime.
 * If you use this class in your preference XML, you don't have to redefine
 * "preference_fallback_accent_color".
 *
 *
 * Copied from https://github.com/Gericop/Android-Support-Preference-V7-Fix
 */
public class PreferenceCategoryCompat extends PreferenceCategory {
    private static final int[] COLOR_ACCENT_ID = new int[]{android.support.v7.appcompat.R.attr.colorAccent};

    public PreferenceCategoryCompat(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        setViewId(android.R.id.title);
    }

    public PreferenceCategoryCompat(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        setViewId(android.R.id.title);
    }

    public PreferenceCategoryCompat(Context context, AttributeSet attrs) {
        super(context, attrs);
        setViewId(android.R.id.title);
    }

    public PreferenceCategoryCompat(Context context) {
        super(context);
        setViewId(android.R.id.title);
    }

    @Override
    public void onBindViewHolder(PreferenceViewHolder holder) {
        super.onBindViewHolder(holder);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
            return;

        final TextView titleView = (TextView) holder.findViewById(android.R.id.title);

        if (titleView != null) {
            final TypedArray typedArray = getContext().obtainStyledAttributes(COLOR_ACCENT_ID);

            if (typedArray.length() > 0) {
                final int accentColor = typedArray.getColor(0, 0xff4081); // defaults to pink
                titleView.setTextColor(accentColor);
            }

            typedArray.recycle();
        }
    }
}
@@ -148,25 +148,100 @@
 oid.
-util.AttributeSet
+support.v4.view.GravityCompat;%0Aimport android.util.AttributeSet;%0Aimport android.view.Gravity
 ;%0Aim
@@ -734,16 +734,62 @@
 egory %7B%0A
+    private static final int PADDING_DP = 14;%0A
     priv
@@ -1889,24 +1889,105 @@
  != null) %7B%0A
+            titleView.setGravity(GravityCompat.START %7C Gravity.CENTER_VERTICAL);%0A
             
@@ -2067,24 +2067,46 @@
 CCENT_ID);%0A%0A
+            try %7B%0A    
             
@@ -2132,24 +2132,28 @@
 th() %3E 0) %7B%0A
+    
             
@@ -2242,32 +2242,36 @@
                 
+ 
+   
 titleView.setTex
@@ -2307,42 +2307,441 @@
     
-%7D%0A%0A            typedArray.recycle(
+    %7D%0A            %7D finally %7B%0A                typedArray.recycle();%0A            %7D%0A%0A            float density = getContext().getResources().getDisplayMetrics().density;%0A            int paddingPx = (int) (density * PADDING_DP);%0A%0A            // View already includes bottom margin. Add padding to all other sides for consistency%0A            // across Android versions.%0A            titleView.setPadding(paddingPx, paddingPx, paddingPx, 0
 );%0A 
@@ -2756,8 +2756,9 @@
 %0A    %7D%0A%7D
+%0A

Fix settings appearance on API 16