0

Need help

I just can't get my title bar/action bar to change colour to RED (#ff0000), it always remains grey.

Styles:

<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="ThemeSelector" parent="android:Theme.Holo.Light">
    <item name="android:actionBarStyle">@style/ActionBar</item>
</style>

<style name="ActionBar" parent="android:style/Widget.Holo.ActionBar">     
    <item name="android:background">#ff0000</item>
</style>
</resources>

Update: (Mainfest)

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.twostarii.actionbardemo"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="11"
    android:targetSdkVersion="19" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/ThemeSelector" >
    <activity
        android:name="com.twostarii.actionbardemo.MainActivity"
        android:label="@string/app_name"
        android:theme="@android:style/Theme" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

Raghunandan
  • 132,755
  • 26
  • 225
  • 256
TwoStarII
  • 351
  • 3
  • 17
  • did you apply the style to the activity in manifest file? – Raghunandan Mar 21 '14 at 12:46
  • Yes, It works when I remove the line: android:theme="@android:style/Theme" > But when I insert the above line so that my image can display I get an error: "you cannot combine custom title with other title features" By the way, my background image is fine on the titlebar / actionbar, the only reason why I want to change the titlebar/ actionbar is because my titlebar image cannot fill parent, there is a bit of grey shade on the sides as well as on the top and bottom so I want to change the titlebar colour to blend with the background image. – TwoStarII Mar 21 '14 at 12:54
  • I don't think you have applied the style to the activity – Raghunandan Mar 21 '14 at 12:56
  • Do you have background drawable and you want to change the color of actionbar?. I don't think both is possible – Raghunandan Mar 21 '14 at 12:59

3 Answers3

1

you can set color for action bar at dynamically,

    public  ActionBar mActionBar;

    mActionBar = getActionBar();
    mActionBar.setBackgroundDrawable(new ColorDrawable(0xff00DDED));
    mActionBar.setDisplayShowTitleEnabled(false);
    mActionBar.setDisplayShowTitleEnabled(true);

or at Static , you should add your style on manifest.xml as,

  android:theme="@style/ThemeSelector"

for your activity

0

you can set color for action bar at dynamically,

    public  ActionBar mActionBar;

    mActionBar = getActionBar();
    mActionBar.setBackgroundDrawable(new ColorDrawable(0xff00DDED));
    mActionBar.setDisplayShowTitleEnabled(false);
    mActionBar.setDisplayShowTitleEnabled(true);
  • My app crashes with that code, also I would like to avoid java wherever possible and work with xml as I already have this defined: //requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); //setContentView(R.layout.activity_main); //getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title_bar); which is commented out for now as I've mentioned: 1) Either I have my title image with grey actionbar OR 2) I have my red actionbar but no image I just can't combine the two – TwoStarII Mar 21 '14 at 13:17
  • @TwoStarII you can't have both – Raghunandan Mar 21 '14 at 13:18
  • I don't see why not, the grey actionbar is just a colour, why can't it be RED and have my red logo image ONTOP of it? – TwoStarII Mar 21 '14 at 13:22
  • @TwoStarII i know you can't but i can't answer the why part. Have a drawable with a color that suits your requirement and have the drawable as a background. If you want give it a try and you will know its not possible – Raghunandan Mar 21 '14 at 13:23
  • Hi, That's what I did but my drawable fails to fill the actiobar, I can still see a bit of grey on the top, bottom and sides so it makes it obvious that my drawable is not my actionbar but instead placed ontop of the actionbar -title_bar.xml: android:id="@+id/logo" android:layout_width="match_parent" android:layout_height="wrap_content" android:scaleType="fitXY" android:gravity="fill_horizontal" android:src="@drawable/logo" android:layout_marginLeft="0dp" – TwoStarII Mar 21 '14 at 14:05
  • @Raghunandan and everyone that helped, resolved here: http://stackoverflow.com/questions/2665507/custom-title-bar-without-padding-android – TwoStarII Mar 21 '14 at 14:41
  • That's exactly what I asked, the link posted also shows a common problem of having the grey areas of the actionbar on the sides of the image, unfortunately due to my reputation I could not upload any screen shots for clarity. – TwoStarII Mar 21 '14 at 15:02
0

You need to change this

android:theme="@android:style/Theme" >

to

android:theme="@style/ThemeSelector" >

in manifest file

Check this for reference

Navigation drawer change color

Community
  • 1
  • 1
Raghunandan
  • 132,755
  • 26
  • 225
  • 256
  • It is set to ThemeSelector under If I change from Theme to ThemeSelector under > I get an error: "error: Error: No resource found that matches the given name (at 'theme' with value '@android:style/ ThemeSelector')." FYI.. I would paste my xml files and java code but I can get the code field (Ctr + K) to work when replying comments – TwoStarII Mar 21 '14 at 13:08
  • @TwoStarII `android:style/ ThemeSelector` that is not the way `"@style/ThemeSelector"` – Raghunandan Mar 21 '14 at 13:10
  • @TwoStarII and you can edit your question and post the update there – Raghunandan Mar 21 '14 at 13:14
  • @TwoStarII change this `android:theme="@android:style/Theme"` to `android:theme="@style/ThemeSelector"`. – Raghunandan Mar 21 '14 at 13:27
  • @TwoStarII atleast you should see the red color now. forget the background drawable. Does it work?? – Raghunandan Mar 21 '14 at 13:41
  • @TwoStarII whatever certainly i was thinking not about the grey area i was thinking the style is not applied at all. – Raghunandan Mar 21 '14 at 15:31
  • Ok, apologies I will try and explain better next time. Thanks for your help. – TwoStarII Mar 21 '14 at 15:45