How to change the color of a specific acitonbar element

I am trying to create an action bar (Android version> = 2.3 with v7 support). I want the color of a specific button to be different from other buttons.

Is there an easy way to do this? Design example below

enter image description here

+3


source to share


5 answers


You can do it from your Activity Class

In onCreate()

your method, Activity

just add these lines and do the necessary imports.



        android.app.ActionBar bar = getActionBar();
        bar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#d44334")));

      

It also works in the support action bar.

+1


source


You can come up with android:actionLayout

in your ad <item>

, post a comment if this is not suitable for you.



0


source


I think this menu is programmed with Java code instead of using the XML menu item. This post can explain a lot about creating menus programmatically.

0


source


Create xml which contains button and set it to menu item

<item
   android:id="@+id/actionViewLayout"
   android:showAsAction="always"
   android:title="Title"
   android:actionLayout="@layout/your_xml_file"
/>

      

0


source


<item
   android:id="@+id/actionViewLayout"
   android:showAsAction="always"
   android:title="Title"
   com.myapp.app:actionLayout="@layout/your_xml_file"
/>

      

It is important that you use your package name instead of "android" when using the SupportActionbar. Also don't forget to add the namespace to the XML.

0


source







All Articles