Android AppCompat Themes -
i'm running through android developer classes, i'd start building apps.
i've downloaded adt package eclipse, i'm familiar eclipse.
i'm playing around themes, reason, project has been set allow appcompat themes. means have use themes theme.appcompat.light. if try use theme.holo or theme.translucent, run time error: illegalstateexception: need use theme.appcompat theme
i've set minimum sdk version in androidmanifest.xml follows:
<uses-sdk android:minsdkversion="11" android:targetsdkversion="19" />
any appreciated.
edited after guillermo's response:
thanks guillermo, hasn't worked. here updated androidmanifest:
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.myfirstapp" android:versioncode="1" android:versionname="1.0" > <uses-sdk android:minsdkversion="14" android:targetsdkversion="19" /> <application android:allowbackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/mybasetheme2" > <activity android:name="com.example.myfirstapp.mainactivity" android:label="@string/app_name" android:theme="@style/mybasetheme1"> <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity> <activity android:name="com.example.myfirstapp.displaymessageactivity" android:label="@string/title_activity_display_message" android:parentactivityname="com.example.myfirstapp.mainactivity" android:theme="@style/mybasetheme2"> <meta-data android:name="android.support.parent_activity" android:value="com.example.myfirstapp.mainactivity" /> </activity> </application> </manifest>
i have following styles.xml file in res/values-14:
<!-- base application theme api 14+. theme replaces appbasetheme both res/values/styles.xml , res/values-v11/styles.xml on api 14+ devices. --> <style name="mybasetheme1" parent="theme.appcompat.light.darkactionbar"> <!-- api 14 theme customizations can go here. --> </style> <style name="mybasetheme2" parent="android:theme.holo.light"> </style> </resources>
i use mybasetheme1 on first activity, loads fine. use mybasetheme2 on second activity, crashes app. if use mybasetheme1 on second activity, works fine, no crashes.
edited add styles files. res/values/styles.xml:
<!-- base application theme, dependent on api level. theme replaced appbasetheme res/values-vxx/styles.xml on newer devices. --> <style name="mybasetheme1" parent="theme.appcompat.light"> <!-- theme customizations available in newer api levels can go in res/values-vxx/styles.xml, while customizations related backward-compatibility can go here. --> </style> <!-- application theme. --> <style name="apptheme" parent="mybasetheme1"> <!-- customizations not specific particular api-level can go here. --> </style> </resources>
res/values-11/styles.xml
<resources> <!-- base application theme api 11+. theme replaces appbasetheme res/values/styles.xml on api 11+ devices. --> <style name="mybasetheme1" parent="theme.appcompat.light"> <!-- api 11 theme customizations can go here. --> </style> </resources>
in activity in you're trying apply different theme, import android.app.activity.
also make sure class extends activity, not actionbaractivity.
when class extends actionbaractivity isrestricted appcompat.light themes
Comments
Post a Comment