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>
rekire
  • 47,260
  • 30
  • 167
  • 264
Tufan
  • 2,789
  • 4
  • 34
  • 52
  • This is your problem : " You need to use a Theme.AppCompat theme (or descendant) with this activity" --> http://stackoverflow.com/questions/21814825/you-need-to-use-a-theme-appcompat-theme-or-descendant-with-this-activity – La masse May 07 '15 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 – Tufan May 07 '15 at 12:49
  • @Tufan Which is your development environment IDE for Eclipse or Studio?. – Sakthivel Appavu May 08 '15 at 08:38
  • @sakthi i use eclipse..is it matter ide – Tufan May 08 '15 at 09:16
  • clear all styles in all values-v11 or v14, just use this style in values/styles.xml, and apply theme to tag in menifest. – Harin May 08 '15 at 12:28

2 Answers2

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.

Maxr1998
  • 1,179
  • 14
  • 22
  • 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 – Tufan May 07 '15 at 13:01
  • U have to use `Theme.AppCompat.DarkActionBar` or `Theme.AppCompat.Light.DarkActionBar` to have a white action bar text.. – Maxr1998 May 07 '15 at 13:20
  • By the way, I also suggest to use the new Toolbar view from support v7 instead of action bar, refer here: http://android-developers.blogspot.de/2014/10/appcompat-v21-material-design-for-pre.html (Chapter **Action Bar**) – Maxr1998 May 07 '15 at 13:22
  • hey @Maxr1998 can we do it programmiticaly – Tufan May 08 '15 at 07:10
  • Yeah of course you can, or do you mean sth different @Tufan? – Maxr1998 May 09 '15 at 08:10
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>
Abdul Rizwan
  • 3,904
  • 32
  • 31