Search code examples
androidandroid-actionbarandroid-themeandroid-actionbar-compat

Apply custom theme in Android Activity


I want to apply custom theme in android action bar title, but when I'm trying to do I got an error.

My Manifest:

 <activity
     android:name="com.lifegoal.eshop.Recharge_Activity"
       android:theme="@style/MyTheme"
        android:label="Mobile Recharge" >

my values v11 text

<!--
    Base application theme for API 11+. This theme completely replaces
    AppBaseTheme from res/values/styles.xml on API 11+ devices.
-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
    <!-- API 11 theme customizations can go here. -->
</style>



 <style name="MyTheme" parent="@android:style/Theme.Holo.Light">
    <item name="android:actionBarStyle">@style/MyActionBar</item>
</style>

<style name="MyActionBar" parent="@android:style/Widget.Holo.Light.ActionBar">
    <item name="android:titleTextStyle">@style/TitleBarTextColor</item>
    <item name="android:background">@color/color_blue</item>
</style>

My Logcat out put

05-07 17:56:40.655: E/AndroidRuntime(1647): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.lifegoal/com.lifegoal.eshop.Recharge_Activity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
05-07 17:56:40.655: E/AndroidRuntime(1647):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)

if anyone know than help me...

<style name="TitleBarTextColor" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title">
    <item name="android:textColor">@color/color_white</item>
</style>


</resources>

Solution

  • As you probably use the AppBaseTheme for your application theme, you would also need a AppCompat theme for the overrriden activities: Your MyTheme needs to have the parent Theme.AppCompat or Theme.AppCompat.Light, not the Holo theme as currenly.