2

My theme is not working I have seen this How do I change the background color of the ActionBar of an ActionBarActivity using XML? but not working still grey only SplahScreen activity changed but MainActivity extend FragmentActivity not: Manifest:

   <application
     android:largeHeap="true"
    android:name="asasdsd.asdasdas"
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher2"
    android:label="@string/app_name"
    android:theme="@style/MyTheme"
   >
    <activity
        android:name="app.sultan.sdcinfo.SplashScreen"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

     <activity
        android:name="app.sultan.sdcinfo.MainActivity"
        android:label="@string/app_name"
                android:theme="@style/MyTheme"
         >
    </activity> 

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

I have localization and add theme file in every Language also in value-11 still not changed:Theme.xml

      `<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:background">#262626</item>
  </style>`

Tried with getActionbar.setBackgroundDrawable(new ColorDrawable("COLOR"));

please look my project structure:splash screen activity then Main activity wich include navigation drawer with fragments in activitis color background changed but not in the fragment

Community
  • 1
  • 1
Sasha
  • 644
  • 8
  • 22

1 Answers1

1

You could not be able to change the actionbar background color because you are not using Widget.Holo.Light.ActionBar.Solid.Inverse as the parent of MyActionBar

use

parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse"

instead of

parent="@android:style/Widget.Holo.Light.ActionBar

So your theme.xml would be like,

<resources>
    <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.Solid.Inverse">
       <item name="android:background">#262626</item>
   </style>
</resources>

Source : Customize ActiobBar Background (Official Documentation)

Apurva
  • 7,871
  • 7
  • 40
  • 59
  • still have problem,all activity actionbars are change but not the Main Activity maybe its because FragmentActivity in Main Activity changed only text color and still grey – Sasha Feb 19 '15 at 16:06
  • I am usig suppport library – Sasha Feb 19 '15 at 16:08
  • @Sultan Did you include the xml code for support library in actionbar theme? What are you saying about text color? – Apurva Feb 19 '15 at 16:15
  • Text color of actionbar goes white and other activities like splashscreen in right color but not MainActivity,how to include:I am using import android.support.v4.app.ActionBarDrawerToggle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentManager; import android.support.v4.widget.DrawerLayout; – Sasha Feb 19 '15 at 16:18
  • you mean @style/MyActionBar yes I include – Sasha Feb 19 '15 at 16:22
  • @Sultan and `#262626` did you include it? – Apurva Feb 19 '15 at 16:23
  • @Sultan and be clear what do you wanna change? background color or text color? I have written code for background color – Apurva Feb 19 '15 at 16:25
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/71276/discussion-between-sultan-and-apurva). – Sasha Feb 19 '15 at 16:26
  • @Sultan I'm sorry, I also am stuck in my own app, let me solve my problem. I really can't. – Apurva Feb 19 '15 at 16:28
  • please look my project structure:splash screen activity then Main activity wich include navigation drawer with fragments in activitis color background changed but not in the fragment – Sasha Feb 19 '15 at 16:29
  • @Sultan http://stackoverflow.com/questions/23993006/change-actionbar-color-in-a-fragment – Apurva Feb 19 '15 at 16:33
  • worked for fragment and should I write it to every fragment there must be other way – Sasha Feb 19 '15 at 16:43
  • Yes you have to write it individually for every fragment, there is no other way. And if my answer really helped you then please accept it. @Sultan – Apurva Feb 19 '15 at 17:10
  • ok, so how can i add menu items on the actionbar in FragmentActivity – Sunil Chaudhary Jul 28 '20 at 12:14