Change action bar color android studio

Change action bar color in android

I am using the app theme Theme.Black in my app. In this theme the action bar is gray. How I can change color of my action bar? This is my attempt:

However, it doesn’t work. Any ideas?

9 Answers 9

it worked for me here

I have Solved Using That.

Just simply go to res/values/styles.xml file and edit the xml file to change the color of xml file .Here is the sample code

if you have in your layout activity_main

you have to put

in your Activity this code

onclick buttons c2 to fetch and change the color of action bar and notification bar according to button’s background, hope this helps

colorlighter is used to set color of notification bar a little lighter than action bar
color is the background color of button c2 , according to which we change our color.

Not the answer you’re looking for? Browse other questions tagged android android-layout or ask your own question.

Linked

Hot Network Questions

Subscribe to RSS

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

site design / logo © 2021 Stack Exchange Inc; user contributions licensed under cc by-sa. rev 2021.12.3.40888

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

Источник

How to set custom ActionBar color / style?

I am using Android Navigation bar in my project, I want to change the top color in action bar to something red, How can i do that? I have something like this,

and i want something like this,

how can i achieve that?

10 Answers 10

You can define the color of the ActionBar (and other stuff) by creating a custom Style:

Simply edit the res/values/styles.xml file of your Android project.

For example like this:

Then set «MyCustomTheme» as the Theme of your Activity that contains the ActionBar.

You can also set a color for the ActionBar like this:

In general Android OS leverages a “theme” to allow app developers to globally apply a universal set of UI element styling parameters to Android applications as a whole, or, alternatively, to a single Activity subclass.

So there are three mainstream Android OS “system themes,” which you can specify in your Android Manifest XML file when you are developing apps for Version 3.0 and later versions

I am referring the (APPCOMPAT)support library here:— So the three themes are 1. AppCompat Light Theme (Theme.AppCompat.Light)

Читайте также:  Autorun manager pro для андроид

  1. AppCompat Dark Theme(Theme.AppCompat),

  1. And a hybrid between these two ,AppCompat Light Theme with the Darker ActionBar.( Theme.AppCompat.Light.DarkActionBar)

AndroidManifest.xml and see the tag, the android theme is mentioned as:— android:theme=»@style/AppTheme»

Open the Styles.xml and we have base application theme declared there:—

We need to override these parent theme elements to style the action bar.

ActionBar with different color background:—

To do this we need to create a new style MyActionBar(you can give any name) with a parent reference to @style/Widget.AppCompat.Light.ActionBar.Solid.Inverse that holds the style characteristics for the Android ActionBar UI element. So definition would be

And this definition we need to reference in our AppTheme, pointing to overridden ActionBar styling as—

@style/MyActionBar

Change the title bar text color (e.g black to white):—

Now to change the title text color, we need to override the parent reference parent=»@style/TextAppearance.AppCompat.Widget.ActionBar.Title»>

So the style definition would be

We’ll reference this style definition inside the MyActionBar style definition, since the TitleTextStyle modification is a child element of an ActionBar parent OS UI element. So the final definition of MyActionBar style element will be

SO this is the final Styles.xml

For further ActionBar options Menu styling, refer this link

Источник

ActionBar text color

how can I change the text color of the ActionBar? I’ve inherited the Holo Light Theme, I’m able to change the background of the ActionBar but I don’t find out what is the attribute to tweak to change the text color.

Ok, I’m able to change the text color with the attribute android:textColorPrimary but it also changes the text color of the dropdown menu displayed when an overflow happen on the ActionBar buttons. Any idea how to change the color of those dropdown menu / List ?

26 Answers 26

Ok, I’ve found a better way. I’m now able to only change the color of the title. You can also tweak the subtitle.

Here is my styles.xml:

I found a way that works well with any flavor of ActionBar (Sherlock, Compat, and Native):

Just use html to set the title, and specify the text color. For example, to set the ActionBar text color to red, simply do this:

You can also use the red hex code #FF0000 instead of the word red . If you are having trouble with this, see Android Html.fromHtml(String) doesn’t work for text .

Additionally, if you want to use a color resource, this code can be used to get the correct HEX String, and removing the alpha if needed (the font tag does not support alpha):

I was having the same problem as you, it’s a Holo.Light theme but I wanted to style the ActionBar color, so I needed to change the text color as well and also both Title and Menus. So at the end I went to git hub and looked at source code until I find the damn correct style:

so now all you have to do is set whatever @color/actionBarText and @drawable/actionbarbground you want!

The ActionBar ID is not available directly, so you have to do little bit of hacking here.

It’s an old topic but for future readers, using ToolBar makes everything very easy:

Читайте также:  Что лучше платформа яндекс или андроид для телевизора

i have done with simple one line code

Add it to the root of the action bar. I had this problem.

actionMenuTextColor — changes text color for the action bar text, it never worked when it was part of the Widget.Styled.ActionBar , so I had to add it to the root. Other 2 attributes change title and subtitle of an action bar.

The most straight-forward way is to do this in the styles.xml.

Google’s template styles.xml currently generates the following:

If you add one more line before the closing tag, as shown, that will change the text color to what it should be with a Dark ActionBar:

If you want to customize the color to something else, you can either specify your own color in colors.xml or even use a built-in color from Android using the android:textColorPrimary attribute:

Note: This changes the color of the title and also the titles of any MenuItems displayed in the ActionBar.

Setting a HTML string on the action bar doesn’t work on the Material theme in SDK v21+

If you want to change it you should set the primary text color in your style.xml

If you want to style the subtitle also then simply add this in your custom style.

People who are looking to get the same result for AppCompat library then this is what I used:

A lot of answers are deprecated so I’ll update the thread and show how to change text color and backgroundcolor on ActionBar (Toolbar) and in ActionBar pop up menu.

The latest approach in Android (as of May 2018) in working with Action bar (Toolbar) is to use Theme with NoActionBar and use Toolbar instead.

so here is what you need:

In Activity (which extends AppCompatActivity) declare Toolbar:

Источник

Android — Change Actionbar Title Text Color

I’m developing an app and I want to change the textcolor of the actionbar title . now, I defined a theme in my manifest:

which is defined in styles.xml:

this doesn’t work but I don’t get why. this should work according to this answer.neither the textview style is working.

what I am doing wrong?

UPDATE: changed to meet Grace Feng answer below

13 Answers 13

Using SpannableString we can set Text Color of Actionbar title

Now, add that style as your theme for toolbar in the XML.

And now you got what you need.

Just add app:titleTextColor=»@color/CUSTOM_COLOR» like so:

wandering around StackOverflow I found this answer which finally worked.

I report it here:

When i got the same problem, i used:

I think it is just the problem of you activity.I used the same code as you, and it works.

Firstly ,i used AppCompatActivity as the base activity and get error. and then i use activity and it works. In my opinion, your code is use for theme for Theme.Holo, and now we use Theme.AppCompat . So if you want change, just reference Changing Background and text color of AppCompat Light DarkActionBar Theme on android. It works for me.Good luck for you.

Seems you’ve used style instead of theme . Styles and themes differ. So replace

Читайте также:  Андроид не показывает надписи

if you change what’s inside the parent=». » to dark or light themes, it adapts the text color to these themes. For example, right now you have a dark theme, and the text is white, but when I change to «Theme.AppCompat.Light» the text color turns black.

Hope it helps in some way.

Change the Activity theme as:

Just had this problem, finally figured it out. In your style.xml do not specify a background color for your toolbar. Then define the color in each layout.xml file:

This gives you the flexibility to be able to easily have different action bar colors depending on the activity if need be as well.

This is a usable code. Follow this code.

In second style tag we customize the actionBar title.

Now Add this above code in the application in Manifest File

Источник

How to Change Background Color of Action Bar in Android?

Kotlin Android – Change Background Color of Action Bar

To change background color of Action Bar in Kotlin Android, set the colorPrimary in themes.xml, with a required color. We can also dynamically change the background color of Action Bar programmatically by setting background drawable for support action bar with the required color drawable.

In this tutorial, we will go through the two processes: via themes.xml and via Kotlin file, to change the background color of Action Bar in Android Application.

Change Background of Action Bar via themes.xml

The following is a step by step process to change the background color of Action Bar in Android Application.

Step 1 – Open themes.xml

1. Click on Resource Manager present on the left side of the Android Studio window.

2. In this Resource Manager window, click on Style tab.

3. Double click on the theme for our application. In this case, Theme.MyApplication.

Theme items present for this theme will be displayed as shown in the following screenshot.

Double click on the default theme.

The contents of this style file, themes.xml, will be displayed in the editor.

Step 2 – Change colors

Now, we have to change color value for the item with the attribute colorPrimary.

Let us assign black color to this item.

Step 3 – Run

Now, let us run this Android Application and observe the background color of Action Bar.

The background color of our Android Application is changed to the set color.

Change Background of Action Bar via Kotlin Activity File

To change the background color of Action Bar programmatically or dynamically, set background drawable for support action bar with the required Color drawable.

In the following example, we set the background color for Action Bar with the color represented by hex value “#146775” in RGB format.

MainActivity.kt

Run the Android Application, and the background color of Action Bar will be set to the color «#146775» , as shown in the following screenshot.

Conclusion

In this Kotlin Android Tutorial, we learned how to change the background color of Floating Action Button (FAB) widget via layout file or programmatically in Kotlin Activity file, with examples.

Источник

Оцените статью