Android Question Must specify preferenceTheme in theme

hookshy

Well-Known Member
Licensed User
Longtime User
I have copied the appcompat preference exemple to my app and got the error below

The main activity already uses app compat and set the theme like this in manifest

B4X:
SetApplicationAttribute(android:theme, "@style/MyAppTheme")

CreateResource(values, theme.xml,
<resources>
    <style name="MyAppTheme" parent="@style/Theme.AppCompat.Light">
        <item name="colorPrimary">#F57C00</item>
        <item name="colorPrimaryDark">#706853</item>
        <item name="colorAccent">#706820</item>
        <item name="windowNoTitle">true</item>
        <item name="windowActionBar">false</item>
        <item name="windowActionModeOverlay">true</item>
    </style>
</resources>
)

The error i got after the activity Pref1 starts:
B4X:
java.lang.IllegalStateException: Must specify preferenceTheme in theme
    at android.support.v7.preference.PreferenceFragmentCompat.onCreate(PreferenceFragmentCompat.java:210)
    at android.support.v4.app.Fragment.performCreate(Fragment.java:2180)
    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1244)
    at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1528)
    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1595)
    at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:758)
    at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2363)
    at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2149)
    at android.support.v4.app.FragmentManagerImpl.optimizeAndExecuteOps(FragmentManager.java:2103)
    at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2013)
    at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:710)
    at android.os.Handler.handleCallback(Handler.java:730)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:5473)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:525)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:854)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:670)
    at dalvik.system.NativeStart.main(Native Method)

Thank you
 

DonManfred

Expert
Licensed User
Longtime User
Check this tutorial. https://www.b4x.com/android/forum/threads/preferences-material-design-preferences.75482/#content

You theme definition is incomplete!

Check the definition from the tutorial:
B4X:
CreateResource(values, theme.xml,
<resources>
    <style name="MyAppTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
        <item name="colorPrimary">#0098FF</item>
        <item name="colorPrimaryDark">#007CF5</item>
        <item name="colorAccent">#FF5522</item>
        <item name="windowNoTitle">true</item>
        <item name="windowActionBar">false</item>
        <item name="preferenceTheme">@style/PreferenceThemeOverlay.Material</item>
        <item name="asp_preferenceIconTint">?colorAccent</item>
        <item name="asp_preferenceDialogIconTint">?asp_preferenceIconTint</item>
        <item name="windowActionModeOverlay">true</item>
    </style>
</resources>
)

Also note that you need this line beside the Theme definition inside the Preferenceactivity.
B4X:
#Extends: de.amberhome.preferences.AppCompatPreferenceActivity
 
Upvote 0
Top