SwitchPreferenceCompat On/Off animation causes left alignment

339 views Asked by At

When I touch a switch, all other switches look normal like below: enter image description here But the switch that is just touched aligns left like below: enter image description here I'm using the following library for preferences screen:

com.android.support:preference-v14:25.3.0

With these styles:

<style name="MyMaterialTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorPrimary</item>
    <item name="preferenceTheme">@style/PrefTheme</item>
</style>

<style name="PrefTheme" parent="PreferenceThemeOverlay">
        <item name="android:textSize">14sp</item>
</style>

XML file:

<PreferenceScreen
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:key="prefscreen"
    android:layout_width="match_parent"
    >
    <PreferenceCategory
        android:title="@string/settings_general"
        android:layout_width="match_parent"
        android:gravity="right"
        >

        <SwitchPreferenceCompat
            android:key="showNotif"
            android:layout_width="match_parent"
            android:gravity="right"
            android:title="@string/settings_notif_menu"
            android:summary="@string/settings_sub_notif_menu" />
    </PreferenceCategory>
    ...
</PreferenceScreen>

It doesn't matter if I use PreferenceThemeOverlay instead of custom style. I've tried both Support Preferences v7 and v14. What am I missing?

Edit: I've noticed CheckBoxPreference behaves the same way.

1

There are 1 answers

0
Sait Banazili On

I found a solution. I was using a PreferenceFragmentCompat in a Fragment. I guess that was causing the problem somehow. Anyway, I've changed my app's architecture to be simpler and problem solved.