1

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> 
5
  • This is your problem : " You need to use a Theme.AppCompat theme (or descendant) with this activity" --> stackoverflow.com/questions/21814825/… Commented May 7, 2015 at 12:44
  • @Lamasse they told usm something like this The reason you are having this problem is because the activity you are trying to apply the dialog theme to is extending ActionBarActivity which requires the AppCompat theme to be applied. Change the Java inheritance from ActionBarActivity to Activity and leave the dialog theme in the manifest as it is but i need to extends actionbar activity...any other way Commented May 7, 2015 at 12:49
  • @Tufan Which is your development environment IDE for Eclipse or Studio?. Commented May 8, 2015 at 8:38
  • @sakthi i use eclipse..is it matter ide Commented May 8, 2015 at 9:16
  • clear all styles in all values-v11 or v14, just use this style in values/styles.xml, and apply theme to <application> tag in menifest. Commented May 8, 2015 at 12:28

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

5 Comments

if i used this its okay its working but if i set action bar title color to red display holo light defalut action bar any soln
U have to use Theme.AppCompat.DarkActionBar or Theme.AppCompat.Light.DarkActionBar to have a white action bar text..
By the way, I also suggest to use the new Toolbar view from support v7 instead of action bar, refer here: android-developers.blogspot.de/2014/10/… (Chapter Action Bar)
hey @Maxr1998 can we do it programmiticaly
Yeah of course you can, or do you mean sth different @Tufan?
1

Follow the below link to design a custom theme
http://jgilfelt.github.io/android-actionbarstylegenerator/

After download the theme you just need to past the files into desired folder and inside AndroidManifesh.xml you need to write your custom theme name.

<application android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/custom_theme_name" > <activity android:name=".MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.