How to set custom ActionBar color / style?
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:
<resources>
<style name="MyCustomTheme" parent="@android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">@style/MyActionBarTheme</item>
</style>
<style name="MyActionBarTheme" parent="@android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">ANY_HEX_COLOR_CODE</item>
</style>
</resources>
Then set "MyCustomTheme" as the Theme of your Activity that contains the ActionBar.
You can also set a color for the ActionBar like this:
ActionBar actionBar = getActionBar();
actionBar.setBackgroundDrawable(new ColorDrawable(Color.RED)); // set your desired color
Taken from here: How do I change the background color of the ActionBar of an ActionBarActivity using XML?
How do I change the background color of the ActionBar of an ActionBarActivity using XML?
As per documentation - "You can control the behaviors and visibility of the action bar with the ActionBar APIs, which were added in Android 3.0 (API level 11)."
So, ActionBar will not work for your target environment which is at API level 10 (Android 2.3.3).
Just in case, if you target for minimum API level 11 , you can change ActionBar's background color by defining custom style, as:
<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">
<item name="android:background">ANY_HEX_COLOR_CODE</item>
</style>
</resources>
And, set "MyTheme" as theme for application / activity.
How to change the color of the actionbar?
You can do it by this way
<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">YOUR_COLOR_CODE</item>
</style>
<style name="TitleBarTextColor" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">YOUR_COLOR_CODE</item>
</style>
Obivously, you have to add this theme on your Activity in your AndroidManifest.
EDIT
Add those imports on your Activity
import android.app.ActionBar;
import android.graphics.drawable.ColorDrawable;
Just below on yout onCreate put this
ActionBar ab = getActionBar();
ColorDrawable colorDrawable = new ColorDrawable(Color.parseColor("#81a3d0"));
ab.setBackgroundDrawable(colorDrawable);
This works for me :
getActionBar().setBackgroundDrawable(new ColorDrawable(0xff1d97dd));
Let me know if it works :)
change actionbar style in android
use local:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
for more details refer https://dzone.com/articles/getting-started-with-android-app-and-material-desi
How to change color of menu icon on custom action bar?
First, define a style that sets colorControlNormal
, making sure to derive from one of the ThemeOverlay
styles:
<style name="MyTheme" parent="@style/ThemeOverlay.AppCompat.ActionBar">
<item name="colorControlNormal">@color/your_color_here</item>
</style>
Then, apply this style to your toolbar in your layout:
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:theme="@style/MyTheme"/>
Android Changing Action Bar color
This is all you need to change the color of the action bar:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#995544</item>
</style>
Setting a custom Style to an Action Bar.xml
This will work for you. You can change the colors of toolbar in colors.xml.
colorPrimary is for ToolBar and colorPrimaryDark is for status bar
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.newapp.toolbarwork.MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<!-- <include layout="@layout/content_main" />-->
</android.support.design.widget.CoordinatorLayout>
MainActivity.java
package com.newapp.toolbarwork;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
colors.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
</resources>
styles.xml
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
Android - Change Actionbar Title Text Color
wandering around StackOverflow I found this answer which finally worked.
I report it here:
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarStyle">@style/ActionBar</item>
...
</style>
<style name="ActionBar" parent="@android:style/Widget.ActionBar">
<item name="android:titleTextStyle">@style/ActionBar.Title</item>
<item name="android:subtitleTextStyle">@style/ActionBar.Subtitle</item>
...
</style>
<style name="ActionBar.Title">
<item name="android:textColor">@color/my_color</item>
</style>
<style name="ActionBar.Subtitle">
<item name="android:textColor">@color/my_color</item>
</style>
Related Topics
Googlesignatureverifier Signature Not Valid Message (Google Play Services 9.0.0)
Get Context of Popupmenu Like Contextmenu
Download the Android Sdk Components for Offline Install
Mediaplayer Stutters at Start of Mp3 Playback
Show Download Progress Inside Activity Using Downloadmanager
Error Importing Holoeverywhere
How to Set Font Custom Font to Spinner Text Programmatically
Android Intercept Paste\Copy\Cut on Edittext
Android Countdowntimer - Additional Milliseconds Delay Between Ticks
Phonegap - Forcing Landscape Orientation
How to Disable Displaying "Suggestions" on the Soft Keyboard
Realmchangelistener Does Not Get Called When Realm Gets Updated in Notificationlistenerservice
Android Action Bar Not Showing Overflow
How to Check If a View Is Visible or Not in Android
How to Customize Item Background and Item Text Color Inside Navigationview
Android: Scrollview Force to Bottom