Set Title Background Color

Set title background color

This thread will get you started with building your own title bar in a xml file and using it in your activities

Edit

Here is a brief summary of the content of the link above - This is just to set the color of the text and the background of the title bar - no resizing, no buttons, just the simpliest sample

res/layout/mytitle.xml - This is the view that will represent the title bar

<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/myTitle"
android:text="This is my new title"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textColor="@color/titletextcolor"
/>

res/values/themes.xml - We want to keep the default android theme and just need to change the background color of the title background. So we create a theme that inherits the default theme and set the background style to our own style.

<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="customTheme" parent="android:Theme">
<item name="android:windowTitleBackgroundStyle">@style/WindowTitleBackground</item>
</style>
</resources>

res/values/styles.xml - This is where we set the theme to use the color we want for the title background

<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="WindowTitleBackground">
<item name="android:background">@color/titlebackgroundcolor</item>
</style>
</resources>

res/values/colors.xml - Set here the color you want

<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="titlebackgroundcolor">#3232CD</color>
<color name="titletextcolor">#FFFF00</color>
</resources>

In the AndroidMANIFEST.xml, set the theme attribute either in the application (for the whole application) or in the activity (only this activity) tags

<activity android:name=".CustomTitleBar" android:theme="@style/customTheme" ...

From the Activity (called CustomTitleBar) :

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.main);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.mytitle);

}

How to change the color of background of title tag?

I did it this way.

<a href="#" title="This is the title to show">hover here</a>
<style type="text/css">
a[title]:hover:after{
content: attr(title);
background: red;
position: absolute;
left: 5%;
top: 10%;}
</style>

You can hide default title by using a data attribute like this

<a href="#" data-title="This is the title to show">hover here</a>
<style type="text/css">
a[data-title]:hover:after{
content: attr(data-title);
background: red;
position: absolute;
left: 5%;
top: 10%;
}
</style>

see more here

Change title background color or making it transparent : android

To Change Window Title bar Color :

Window window = activity.getWindow();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.setStatusBarColor(ContextCompat.getColor(activity, R.color.yourColor));
}

for api<21 , :

<resources>
<style name="AppTheme" parent="android:Theme.Material">
<!-- Customize your theme using Material Design here. -->
<!-- Title Bar color here -->
<item name="android:colorPrimary">#YOUR_COLOR_HERE</item>
<!-- Background color here -->
<item name="android:windowBackground">#YOUR_COLOR_HERE</item>
</style>
</resources>

change the background color of the title in UIButton

The full answer is :

 btn.tintColor = UIColor.clear  //if we have different tint, which I had 
btn.titleLabel?.backgroundColor = UIColor.clear

How do you set the title color for the new Toolbar?

Option 1) The quick and easy way (Toolbar only)

Since appcompat-v7-r23 you can use the following attributes directly on your Toolbar or its style:

app:titleTextColor="@color/primary_text"
app:subtitleTextColor="@color/secondary_text"

If your minimum SDK is 23 and you use native Toolbar just change the namespace prefix to android.

In Java you can use the following methods:

toolbar.setTitleTextColor(Color.WHITE);
toolbar.setSubtitleTextColor(Color.WHITE);

These methods take a color int not a color resource ID!

Option 2) Override Toolbar style and theme attributes

layout/xxx.xml

<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:theme="@style/ThemeOverlay.MyApp.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
style="@style/Widget.MyApp.Toolbar.Solid"/>

values/styles.xml

<style name="Widget.MyApp.Toolbar.Solid" parent="Widget.AppCompat.ActionBar">
<item name="android:background">@color/actionbar_color</item>
<item name="android:elevation" tools:ignore="NewApi">4dp</item>
<item name="titleTextAppearance">...</item>
</style>

<style name="ThemeOverlay.MyApp.ActionBar" parent="ThemeOverlay.AppCompat.ActionBar">
<!-- Parent theme sets colorControlNormal to textColorPrimary. -->
<item name="android:textColorPrimary">@color/actionbar_title_text</item>
</style>

Help! My icons changed color too!

@PeterKnut reported this affects the color of overflow button, navigation drawer button and back button. It also changes text color of SearchView.

Concerning the icon colors: The colorControlNormal inherits from

  • android:textColorPrimary for dark themes (white on black)
  • android:textColorSecondary for light themes (black on white)

If you apply this to the action bar's theme, you can customize the icon color.

<item name="colorControlNormal">#de000000</item>

There was a bug in appcompat-v7 up to r23 which required you to also override the native counterpart like so:

<item name="android:colorControlNormal" tools:ignore="NewApi">?colorControlNormal</item>

Help! My SearchView is a mess!

Note: This section is possibly obsolete.

Since you use the search widget which for some reason uses different back arrow (not visually, technically) than the one included with appcompat-v7, you have to set it manually in the app's theme. Support library's drawables get tinted correctly. Otherwise it would be always white.

<item name="homeAsUpIndicator">@drawable/abc_ic_ab_back_mtrl_am_alpha</item>

As for the search view text...there's no easy way. After digging through its source I found a way to get to the text view. I haven't tested this so please let me know in the comments if this didn't work.

SearchView sv = ...; // get your search view instance in onCreateOptionsMenu
// prefix identifier with "android:" if you're using native SearchView
TextView tv = sv.findViewById(getResources().getIdentifier("id/search_src_text", null, null));
tv.setTextColor(Color.GREEN); // and of course specify your own color

Bonus: Override ActionBar style and theme attributes

Appropriate styling for a default action appcompat-v7 action bar would look like this:

<!-- ActionBar vs Toolbar. -->
<style name="Widget.MyApp.ActionBar.Solid" parent="Widget.AppCompat.ActionBar.Solid">
<item name="background">@color/actionbar_color</item> <!-- No prefix. -->
<item name="elevation">4dp</item> <!-- No prefix. -->
<item name="titleTextStyle">...</item> <!-- Style vs appearance. -->
</style>

<style name="Theme.MyApp" parent="Theme.AppCompat">
<item name="actionBarStyle">@style/Widget.MyApp.ActionBar.Solid</item>
<item name="actionBarTheme">@style/ThemeOverlay.MyApp.ActionBar</item>
<item name="actionBarPopupTheme">@style/ThemeOverlay.AppCompat.Light</item>
</style>

How to change the title background color of the dialog?

Recently I used it for my implementation, so here is my code.

You can do that by creating a new style in the styles.xml file:

<style name="question_dialog" parent="@android:style/Theme.Holo.Dialog">
<item name="android:windowTitleStyle">@style/question_dialog_title</item>
</style>

<style name="question_dialog_title" parent="android:Widget.TextView">
<item name="android:background">#5cc5cc</item>
<item name="android:textSize">21sp</item>
<item name="android:textColor">#ffffff</item>
</style>

and then, when you create your Dialog object, you wanna use this constructor:

answeringDialog = new Dialog(this, R.style.question_dialog);

the output is:

Sample Image

Change title background color in ExtJS Panel

FIDDLE

Here's the style:

.myCls .x-panel-header-default {
background-color: green;
}

And you define the cls in panel properties:

cls: 'myCls'


Related Topics



Leave a reply



Submit