Create custom titlebar in Android - android

I created a custom title bar for my application but I am having some problems implementing it. I want to change the color and the appearance for the text and title bar
The layout of the styles.xml is as below:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyTheme">
<item name="android:tabWidgetStyle">#style/LightTabWidget</item>
</style>
<style name="MyWindowTitleBackground" parent="#android:style/WindowTitleBackground">
<item name="android:background">#android:drawable/title_bar</item>
</style>
<style name="MyWindowTitle" parent="#android:style/WindowTitle">
<item name="android:singleLine">true</item>
<item name="android:windowTitleSize">40dip</item>
<item name="android:textAppearance">#style/MyTextAppearance</item>
<item name="android:shadowColor">#BB000000</item>
<item name="android:shadowRadius">2.75</item>
</style>
<style name="MyTextAppearance" parent="#android:style/TextAppearance.WindowTitle">
<item name="android:textColor">#3A6629</item>
<item name="android:textSize">14sp</item>
<item name="android:textStyle">bold</item>
</style>
<style name="LightTabWidget" parent="#android:style/Widget.TabWidget">
<item name="android:textSize">20px</item>
<item name="android:textStyle">bold</item>
<item name="android:textColor">#FF5721</item>
</style>
</resources>
And I have added that theme in the manifest file as follows:
<application android:icon="#drawable/icon" android:label="#string/app_name" android:theme="#android:style/Theme.Light">
<activity android:name="LAFoodBankAboutUs" android:label="#string/app_name" android:theme="#style/MyTheme">
What do I have to do to show the custom title bar?

By now (after some years), the Toolbar is available. It features a lot of customization possibilities and is also available via the Support Library

Related

ActionBar Custom Title Color

<?xml version="1.0" encoding="utf-8"?>
<style name="OmlActionBarTheme" parent="#android:style/Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/OmlActionBar</item>
<item name="android:homeAsUpIndicator">#drawable/back_arrow</item>
<item name="android:titleTextStyle">#style/OmlActionBarTitle</item>
<item name="android:subtitleTextStyle">#style/OmlActionBarSubTitle</item>
</style>
<style name="OmlActionBar" parent="#android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">#color/action_bar_white</item>
</style>
<style name="OmlActionBarTitle" parent="#android:style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">#color/action_bar_blue</item>
</style>
<style name="OmlActionBarSubTitle" parent="#android:style/TextAppearance.Holo.Widget.ActionBar.Subtitle">
<item name="android:textColor">#color/action_bar_blue</item>
</style>
Hi,I need to customize my actionBar title Text Color and subTitle Text Color. I used the above style but there is no change.
Try The Following...
style.xml
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
<item name="android:windowBackground">#drawable/login_background</item>
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar"
parent="#android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">#color/theme_blue</item>
<item name="titleTextStyle">#style/ActionBarTitleText</item>
<item name="subtitleTextStyle">#style/ActionBarSubTitleText</item>
</style>
<style name="ActionBarTitleText" parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#color/stdDarkBlueText</item>
<item name="android:textSize">12sp</item>
</style>
<style name="ActionBarSubTitleText" parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Subtitle">
<item name="android:textColor">#color/stdDarkBlueText</item>
<item name="android:textSize">12sp</item>
</style>
</resources>
Apply this theme to your application in Manifest File..
AndroidManifest.xml
<application
android:allowBackup="true"
android:icon="#drawable/ic_icon128"
android:label="#string/app_name"
android:theme="#style/AppTheme" // apply theme here
android:windowSoftInputMode="stateHidden" >
i have done with simple one line code
actionBar.setTitle(Html.fromHtml("<font color='#ff0000'>ActionBartitle </font>"));

Android apply different Text Selection Handles

I've created the bellow style to change the selection handles on an EditText.
<style name="AutoCompleteTextViewOrangeAutoComplete" parent="android:Widget.Holo.Light.AutoCompleteTextView">
<item name="android:dropDownSelector">#drawable/orangeautocomplete_list_selector_holo_light</item>
<item name="android:background">#drawable/orangeautocomplete_edit_text_holo_light</item>
<item name="android:textSelectHandle">#drawable/orangehandle_text_select_handle_middle</item>
<item name="android:textSelectHandleLeft">#drawable/orangehandle_text_select_handle_left</item>
<item name="android:textSelectHandleRight">#drawable/orangehandle_text_select_handle_right</item>
<item name="android:textColorHighlight">#99db4b39</item>
</style>
On my layouts, some of my TextViews can be selected so I want to apply the same selection handles but since I have many TextViewsI would like to apply the handles to all of my app.
On AndroidManifest I have this:
<activity
android:name=".Fragments"
android:exported="false"
android:label="#string/app_name"
android:theme="#style/myTheme">
And on Values-v14 my styles.xml is like this:
<resources>
<style name="myTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:textViewStyle">#style/test</item>
</style>
<style name="test" parent="android:Widget.Holo.Light.TextView">
<item name="android:textSelectHandle">#drawable/orangehandle_text_select_handle_middle</item>
<item name="android:textSelectHandleLeft">#drawable/orangehandle_text_select_handle_left</item>
<item name="android:textSelectHandleRight">#drawable/orangehandle_text_select_handle_right</item>
<item name="android:textColorHighlight">#99db4b39</item>
</style>
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar"/>
</resources>
Unfortunately this is not changing the default text selection handles.
Any idea how to make it work?

AppCompat Title color

I'm having some troubles changing the color for the ActionBar. I'm using AppCompat library for support. Everything else works: like background, or selector ... but the title color isn't changing.
This is my style file:
<resources xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools">
<style name="Theme.Customtitletheme" parent="#style/Theme.AppCompat.Light">
<item name="actionBarItemBackground">#drawable/selectable_background_customtitletheme</item>
<item name="android:actionBarItemBackground" tools:targetApi="14">#drawable/selectable_background_customtitletheme</item>
<item name="popupMenuStyle">#style/PopupMenu.Customtitletheme</item>
<item name="android:popupMenuStyle" tools:targetApi="11">#style/PopupMenu.Customtitletheme</item>
<item name="dropDownListViewStyle">#style/DropDownListView.Customtitletheme</item>
<item name="android:dropDownListViewStyle">#style/DropDownListView.Customtitletheme</item>
<item name="actionBarTabStyle">#style/ActionBarTabStyle.Customtitletheme</item>
<item name="android:actionBarTabStyle" tools:targetApi="11">#style/ActionBarTabStyle.Customtitletheme</item>
<item name="actionDropDownStyle">#style/DropDownNav.Customtitletheme</item>
<item name="android:actionDropDownStyle" tools:targetApi="11">#style/DropDownNav.Customtitletheme</item>
<item name="actionBarStyle">#style/ActionBar.Solid.Customtitletheme</item>
<item name="android:actionBarStyle" tools:targetApi="11">#style/ActionBar.Solid.Customtitletheme</item>
<item name="actionModeBackground">#drawable/cab_background_top_customtitletheme</item>
<item name="android:actionModeBackground" tools:targetApi="11">#drawable/cab_background_top_customtitletheme</item>
<item name="actionModeSplitBackground">#drawable/cab_background_bottom_customtitletheme</item>
<item name="android:actionModeSplitBackground" tools:targetApi="14">#drawable/cab_background_bottom_customtitletheme</item>
<item name="actionModeCloseButtonStyle">#style/ActionButton.CloseMode.Customtitletheme</item>
<item name="android:actionModeCloseButtonStyle" tools:targetApi="11">#style/ActionButton.CloseMode.Customtitletheme</item>
<item name="actionMenuTextColor">#color/actionbar_text</item>
<item name="android:actionMenuTextColor" tools:targetApi="11">#color/actionbar_text</item>
</style>
<style name="ActionBar.Solid.Customtitletheme" parent="#style/Widget.AppCompat.Light.ActionBar.Solid">
<item name="background">#drawable/ab_solid_customtitletheme</item>
<item name="android:background">#drawable/ab_background_textured_customtitletheme</item>
<item name="backgroundStacked">#drawable/ab_stacked_solid_customtitletheme</item>
<item name="android:backgroundStacked" tools:targetApi="14">#drawable/ab_stacked_solid_customtitletheme</item>
<item name="backgroundSplit">#drawable/ab_bottom_solid_customtitletheme</item>
<item name="android:backgroundSplit" tools:targetApi="14">#drawable/ab_background_textured_customtitletheme</item>
<item name="progressBarStyle">#style/ProgressBar.Customtitletheme</item>
<item name="android:progressBarStyle">#style/ProgressBar.Customtitletheme</item>
<item name="titleTextStyle">#style/ActionBar.CustomTitle</item>
<item name="android:textStyle">#style/ActionBar.CustomTitle</item>
</style>
<style name="PopupMenu.Customtitletheme" parent="#style/Widget.AppCompat.Light.PopupMenu">
<item name="android:popupBackground">#drawable/menu_dropdown_panel_customtitletheme</item>
</style>
<style name="DropDownListView.Customtitletheme" parent="#style/Widget.AppCompat.Light.ListView.DropDown">
<item name="android:listSelector">#drawable/selectable_background_customtitletheme</item>
</style>
<style name="ActionBarTabStyle.Customtitletheme" parent="#style/Widget.AppCompat.Light.ActionBar.TabView">
<item name="android:background">#drawable/tab_indicator_ab_customtitletheme</item>
</style>
<style name="DropDownNav.Customtitletheme" parent="#style/Widget.AppCompat.Light.Spinner.DropDown.ActionBar">
<item name="android:background">#drawable/spinner_background_ab_customtitletheme</item>
<item name="android:popupBackground">#drawable/menu_dropdown_panel_customtitletheme</item>
<item name="android:dropDownSelector">#drawable/selectable_background_customtitletheme</item>
</style>
<style name="ProgressBar.Customtitletheme" parent="#style/Widget.AppCompat.ProgressBar.Horizontal">
<item name="android:progressDrawable">#drawable/progress_horizontal_customtitletheme</item>
</style>
<style name="ActionButton.CloseMode.Customtitletheme" parent="#style/Widget.AppCompat.Light.ActionButton.CloseMode">
<item name="android:background">#drawable/btn_cab_done_customtitletheme</item>
</style>
<!-- ActionBar title text -->
<style name="ActionBar.CustomTitle" parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#color/actionbar_text</item>
<!-- The textColor property is backward compatible with the Support Library -->
</style>
<!-- this style is only referenced in a Light.DarkActionBar based theme -->
<style name="Theme.Customtitletheme.Widget" parent="#style/Theme.AppCompat">
<item name="popupMenuStyle">#style/PopupMenu.Customtitletheme</item>
<item name="android:popupMenuStyle" tools:targetApi="11">#style/PopupMenu.Customtitletheme</item>
<item name="dropDownListViewStyle">#style/DropDownListView.Customtitletheme</item>
<item name="android:dropDownListViewStyle">#style/DropDownListView.Customtitletheme</item>
</style>
</resources>
I have also used different values folders, like values-v14 or values-v11, but the same result.
If I change the parent from "Theme.AppCompat.Light" to "Theme.AppCompat.Dark" the color changes, but when I want to use some custom color it is not working...
Also, this is how I used the specified theme in manifest:
<activity
android:name="com.cos.ShareActivity"
android:label="Share File"
android:parentActivityName="com.cos.FileManagerActivity"
android:theme="#style/Theme.Customtitletheme" >
<!-- Parent activity meta-data to support 4.0 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.cos.FileManagerActivity" />
</activity>
What I am doing wrong that the color item is ignored ?
After so much time lost trying to figure it out, I found that it was a typo ... damn ... I have used android:textStyle instead of android:titleTextStyle. When I typed in that line the IDE auto-suggest typed the first one :(

Android: Title Bar Color don't change

I wanna change my Apps Titlebar color and tried it in this way:
Part of the manifest file:
<application
android:icon="#drawable/icon"
android:label="#string/app_name"
android:theme="#style/Theme.MyTitleBar" ></application>
The style block part of the file styles.xml:
<style name="Theme.MyTitleBar" parent="android:Theme">
<item name="android:colorBackground">#FFFFFF</item>
<item name="android:background">#FFFFFF</item>
<item name="android:textColor">#android:color/black</item>
<item name="android:textStyle">bold</item>
<item name="android:textSize">16sp</item>
</style>
But only the text color and attributes changes correct. Any guest what I did wrong?
EDIT: I added the part for the ActionBar (sorry I put only for Dialogs at first)
You can follow this, it will allow you to change moreover other attributes that just the title bar:
Just call your custom theme in the manifest file:
<application
android:icon="#drawable/icon"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
Then create these 2 styles in your styles.xml. The first one defines the theme, the second one, one of the styles to apply on the theme:
<style name="AppTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/ActionBarStyle</item>
</style>
<style name="ActionBarStyle" parent="android:style/Widget.Holo.Light.ActionBar">
<item name="android:colorBackground">#FFFFFF</item>
<item name="android:background">#FFFFFF</item>
<item name="android:textColor">#android:color/black</item>
<item name="android:textStyle">bold</item>
<item name="android:textSize">16sp</item>
</style>
NOTE: In this example, I customize the theme Holo Light as you can see with this: android:style/Widget.Holo.Light.ActionBar.
Add This style.xml File in your project according to your requirment...
<item name="android:actionBarStyle">#style/myActionBar</item>
</style>
<style name="myActionBar" parent="#android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:titleTextStyle">#style/myActionBar.titleTextStyle</item>
</style>
<style name="myActionBar.titleTextStyle" parent="#android:style/TextAppearance.Holo.Widget.ActionBar.Title.Inverse">
<item name="android:textColor">#color/darkgrey</item>
</style>
<style name="myActionBar" parent="#android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">#e6ebc3</item>
</style>

Themes overriding each other?

In my styles.xml file I have a style to remove the title bar and other styles to change my tabwidget's font size:
<?xml version="1.0" encoding="utf-8"?>
<style name="RemoveTitleBar" parent="android:Theme">
<item name="android:style/Theme.Black.NoTitleBar.Fullscreen">true</item>
<item name="android:windowNoTitle">true</item>
</style>
<style name="CustomTheme" parent="android:style/Theme">
<item name="android:tabWidgetStyle">#style/CustomTabWidget</item>
</style>
<style name="CustomTabWidget" parent="android:style/Widget.TabWidget">
<item name="android:textAppearance">#style/CustomTabWidgetText</item>
</style>
<style name="CustomTabWidgetText" parent="android:style/TextAppearance.Widget.TabWidget">
<item name="android:textSize">12sp</item>
<item name="android:textStyle">bold</item>
</style>
In my AndroidManifest.xml file I set the RemoveTitleBar style to the application which works fine:
<application
android:icon="#drawable/ic_launcher_test_icon"
android:label="#string/app_name"
android:theme="#style/RemoveTitleBar"
....
However when I apply the CustomTheme style to my activity with tabs, I get the title bar back. But if I remove the line it works fine.
<activity android:name=".TabActivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:theme="#style/CustomTheme"> </activity>
Am I going about this the wrong way or do I have to change something in my styles.xml file? Thanks for you time.
You are extending CustomTheme with "android:style/Theme":
<style name="CustomTheme" parent="android:style/Theme">
<item name="android:tabWidgetStyle">#style/CustomTabWidget</item>
</style>
and the titleBar is available in in this you aren't removing the titleBar, you will again need to remove the titleBar like this:
<style name="CustomTheme" parent="android:style/Theme">
<item name="android:tabWidgetStyle">#style/CustomTabWidget</item>
<item name="android:style/Theme.Black.NoTitleBar.Fullscreen">true</item>
</style>

Categories

Resources