Android action bar autosrollable title - android

I'd like to create app with setTitle function at ActionBar
But, some strings are bigger than ActionBar width, and i want use autoscrollable function for my title.
I try to create style for my ActionBar:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<!-- Support library compatibility -->
<item name="actionBarStyle">#style/MyActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar" parent="Widget.AppCompat.ActionBar.Solid">
<item name="android:background">#drawable/ab_background</item>
<item name="android:titleTextStyle">#style/ActionBarTitleStyle</item>
<!-- Support library compatibility -->
<item name="background">#drawable/ab_background</item>
<item name="titleTextStyle">#style/ActionBarTitleStyle</item>
</style>
<style name="ActionBarTitleStyle" parent="TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:ellipsize">marquee</item>
<item name="android:marqueeRepeatLimit">1</item>
<item name="android:singleLine">true</item>
<item name="android:focusable">true</item>
<item name="android:focusableInTouchMode">true</item>
<item name="android:textColor">#FF64A3</item>
</style>
But it doesn't work.
Please tell me what i do wrong?

Related

How do I customize menu item's background color?

I'm trying to customize Toolbar's popup menu. Now I can not set background color of menu item.
My styles.xml looks like this:
<resources>
<!-- Base application theme. -->
<style name="AppTheme.NoActionBar" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:actionBarStyle">#style/AppTheme.ActionBar</item>
<item name="android:actionMenuTextColor">#color/actionbar_text_color</item>
<item name="android:dropDownListViewStyle">#style/AppTheme.DropDown</item>
<item name="android:itemTextAppearance">#style/menuItemColor</item>
<!-- Support library compatibility -->
<item name="actionBarStyle">#style/AppTheme.ActionBar</item>
<item name="actionMenuTextColor">#color/actionbar_text_color</item>
<item name="dropDownListViewStyle">#style/AppTheme.DropDown</item>
<item name="itemTextAppearance">#style/menuItemColor</item>
</style>
<style name="AppTheme.ActionBar" parent="#style/ThemeOverlay.AppCompat.Dark.ActionBar">\
<item name="titleTextColor">#color/actionbar_text_color</item>
<item name="subtitleTextColor">#color/actionbar_text_color</item>
<item name="android:background">#color/actionbar_background</item>
<!-- Support library compatibility -->
<item name="background">#color/actionbar_background</item>
</style>
<style name="AppTheme.DropDown" parent="#style/Widget.AppCompat.Light.ListView.DropDown">
<item name="android:background">#color/background_color</item>
<!-- Support library compatibility -->
<item name="background">#color/background_color</item>
</style>
<style name="menuItemColor">
<item name="android:textColor">#color/inactive_text_color</item>
</style>
</resources>
I added ActionBar to activity layout with code
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:theme="#style/AppTheme.ActionBar"/>
Note: I'm using AppCompat, not Holo or other.
This may help you,create a style like,
<style name="PopupMenu" parent="#android:style/Widget.PopupMenu">
<item name="android:popupBackground">#android:color/white</item>
and add it to your main themes..
<style name="AppTheme.NoActionBar" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:popupMenuStyle">#style/PopupMenu</item> <! added it here
<item name="android:actionBarStyle">#style/AppTheme.ActionBar</item>
<item name="android:actionMenuTextColor">#color/actionbar_text_color</item>
<item name="android:textColor">#color/text_color</item>
<!-- Support library compatibility -->
<item name="actionBarStyle">#style/AppTheme.ActionBar</item>
<item name="actionMenuTextColor">#color/actionbar_text_color</item>
</style>
<style name="AppTheme.ActionBar" parent="#style/ThemeOverlay.AppCompat.Dark.ActionBar">\
<item name="titleTextColor">#color/actionbar_text_color</item>
<item name="subtitleTextColor">#color/actionbar_text_color</item>
<item name="android:popupMenuStyle">#style/PopupMenu</item> <! added it here
<item name="android:background">#color/actionbar_background</item>
<!-- Support library compatibility -->
<item name="background">#color/actionbar_background</item>
</style>
You have to define style for Overflow Menu too like this :
<!-- OverFlow menu Styles -->
<style name="PopupMenuListView" parent="#style/Widget.AppCompat.Light.ListView.DropDown">
<item name="android:divider">#color/sp_red_500</item>
<item name="android:dividerHeight">1dp</item>
<item name="android:background">#color/white</item>
</style>
and in your parent theme style( Base application theme.) define drop down menu style like this :
<item name="dropDownListViewStyle">#style/PopupMenuListView</item>

Transparent Overlay ActionBar with AppCompat?

I would like to have an ActionBar with the following properties:
Overlay bar, so that the layout's parent view will stretch to full the whole window.
A white title color for the ActionBar.
Transparent background.
I'm targeting API 14+, with AppCompat-v7:22.2.1. So I prepare my styles like this:
<style name="Theme.MyTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/Theme.MyTheme.MyActionBar</item>
<item name="actionBarStyle">#style/Theme.MyTheme.MyActionBar</item>
<item name="colorPrimary">#5af142</item>
<item name="colorPrimaryDark">#06dd09</item>
<item name="colorAccent">#20f304</item>
</style>
<style name="Theme.MyTheme.MyActionBar" parent="#style/Widget.AppCompat.ActionBar">
<item name="android:background">#android:color/transparent</item>
<item name="background">#android:color/transparent</item>
<item name="android:windowActionBarOverlay">true</item>
<item name="windowActionBarOverlay">true</item>
<item name="android:textColor">#android:color/white</item>
</style>
And, in the Manifest, I set Theme.MyTheme as my activity's theme.
1 & 2 are working, 3 is not. It seams that I get a grey-ish background, and I don't know what should I change/add.
Try out below code, which is my styles.xml
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!--<item name="android:windowActionBarOverlay">true</item>
<item name="windowActionBarOverlay">true</item>-->
<item name="android:windowActionBarOverlay">true</item>
<item name="android:actionBarStyle">#style/MyActionBar</item>
<!-- Support library compatibility -->
<item name="windowActionBarOverlay">true</item>
<item name="actionBarStyle">#style/MyActionBar</item>
<item name="android:windowContentOverlay">#null</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar"
parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#color/transparent</item>
<item name="android:titleTextStyle">#style/Theme.YourTheme.Styled.ActionBar.TitleTextStyle</item>
<!-- Support library compatibility -->
<item name="background">#color/transparent</item>
<item name="titleTextStyle">#style/Theme.YourTheme.Styled.ActionBar.TitleTextStyle</item>
</style>
<style name="Theme.YourTheme.Styled.ActionBar.TitleTextStyle" parent="#android:style/Widget.TextView">
<item name="android:textSize">13sp</item>
<item name="android:textStyle">bold</item>
<item name="android:textColor">#android:color/white</item>
<item name="textSize">13sp</item>
<item name="textStyle">bold</item>
<item name="textColor">#android:color/white</item>
</style>
</resources>

Android how to change action bar backbutton and overflow button background color on pressed state?

I want to change the background color of the backbutton and overflowmenu button on pressed state.
I am using ActionBarActivity . Appcompact v7 library.
Programmatically is it possible to change background color of the back button and overflowmenubutton ?
Below is my styles:
<resources>
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
<!-- <item name="windowActionBar">false</item> -->
</style>
<style name="ActionBar.Solid.Sri" parent="#style/Widget.AppCompat.Light.ActionBar.Solid">
<item name="background">#drawable/ab_solid_sri</item>
<item name="backgroundStacked">#drawable/ab_stacked_solid_sri</item>
<item name="backgroundSplit">#drawable/ab_bottom_solid_sri</item>
<item name="progressBarStyle">#style/ProgressBar</item>
</style>
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:actionBarDivider">#color/action_bar_text_color</item>
<item name="actionBarDivider">#color/action_bar_text_color</item>
<item name="actionBarItemBackground">#drawable/selectable_background_sri</item>
<item name="android:actionBarStyle">#style/ActionBar.Transparent</item>
<item name="actionBarStyle">#style/ActionBar.Transparent</item>
<!--
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="actionBarStyle">#style/MyActionBar</item>
-->
<item name="actionOverflowMenuStyle">#style/OverflowMenu</item>
<item name="popupMenuStyle">#style/PopupMenu</item>
<item name="dropDownListViewStyle">#style/DropDownListView</item>
<item name="android:popupMenuStyle">#style/PopupMenu</item>
<item name="android:dropDownListViewStyle">#style/DropDownListView</item>
<item name="actionModeBackground">#drawable/cab_background_top_sri</item>
<item name="actionModeSplitBackground">#drawable/cab_background_bottom_sri</item>
<item name="actionModeCloseButtonStyle">#style/ActionButton.CloseMode</item>
<!--
<item name="actionOverflowButtonStyle">#style/OverFlowStyle</item>
<item name="android:actionOverflowButtonStyle">#style/OverFlowStyle</item>
-->
<item name="actionDropDownStyle">#style/DropDownNav</item>
<item name="android:actionDropDownStyle">#style/DropDownNav</item>
<item name="android:actionBarTabTextStyle">#style/TabTextStyle</item>
<item name="actionBarTabTextStyle">#style/TabTextStyle</item>
<item name="actionBarTabStyle">#style/ActionBarTabStyle</item>
<item name="android:actionBarTabStyle">#style/ActionBarTabStyle</item>
<!-- <item name="actionBarStyle">#style/Theme.MyApp.ActionBar</item> -->
</style>
<style name="ActionButton.CloseMode" parent="#style/Widget.AppCompat.Light.ActionButton.CloseMode">
<item name="android:background">#drawable/btn_cab_done_sri</item>
</style>
<style name="DropDownListView" parent="#style/Widget.AppCompat.Light.ListView.DropDown">
<item name="android:listSelector">#drawable/selectable_background_sri</item>
</style>
<style name="PopupMenu" parent="#style/Widget.AppCompat.Light.PopupMenu">
<item name="android:popupBackground">#drawable/menu_dropdown_panel_sri</item>
</style>
<style name="MyActionBar" parent="#style/Widget.AppCompat.ActionBar">
<item name="android:titleTextStyle">#style/TitleTextStyle</item>
<!-- Support library compatibility -->
<item name="titleTextStyle">#style/TitleTextStyle</item>
</style>
<style name="ActionBar.Transparent" parent="#style/Widget.AppCompat.Light.ActionBar">
<item name="background">#drawable/ab_transparent_sri</item>
<item name="progressBarStyle">#style/ProgressBar</item>
<item name="android:titleTextStyle">#style/TitleTextStyle</item>
<!-- Support library compatibility -->
<item name="titleTextStyle">#style/TitleTextStyle</item>
</style>
<style name="ProgressBar" parent="#style/Widget.AppCompat.ProgressBar.Horizontal">
<item name="android:progressDrawable">#drawable/progress_horizontal_sri</item>
</style>
<style name="OverFlowStyle" parent="#style/Widget.AppCompat.Light.ActionButton.Overflow">
<item name="android:src">#drawable/ic_empty</item>
</style>
<style name="TitleTextStyle" parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#color/action_bar_text_color</item>
</style>
<style name="TabTextStyle" parent="#style/Widget.AppCompat.ActionBar.TabText">
<item name="android:textColor">#color/action_bar_text_color</item>
</style>
<style name="ActionBarTabStyle" parent="#style/Widget.AppCompat.Light.ActionBar.TabView">
<item name="android:background">#drawable/tab_indicator_ab_sri</item>
<item name="background">#drawable/tab_indicator_ab_sri</item>
</style>
<style name="DropDownNav" parent="#style/Widget.AppCompat.Light.Spinner.DropDown.ActionBar">
<item name="android:background">#drawable/spinner_background_ab_sri</item>
<item name="android:popupBackground">#drawable/menu_dropdown_panel_sri</item>
<item name="android:dropDownSelector">#drawable/selectable_background_sri</item>
<item name="background">#drawable/spinner_background_ab_sri</item>
</style>
<!--
<style name="Theme.MyApp.ActionBar" parent="style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
remove shadow below action bar
<item name="android:elevation">0dp</item>
Support library compatibility
<item name="elevation">0dp</item>
<item name="android:windowContentOverlay">#null</item>
</style>
-->
<style name="OverflowMenu" parent="Widget.AppCompat.PopupMenu.Overflow">
<!-- Required for pre-Lollipop. -->
<item name="overlapAnchor">false</item>
<!-- Required for Lollipop. -->
<!-- <item name="android:overlapAnchor">false</item> -->
</style>
<style name="ProgressBarStyle" parent="#android:style/Widget.ProgressBar.Horizontal" />
<!--
<style name="MyActionBar" parent="#style/Widget.AppCompat.ActionBar">
<item name="android:background">#drawable/actionbar_background</item>
<item name="android:windowActionBarOverlay">true</item>
Support library compatibility
<item name="background">#drawable/actionbar_background</item>
<item name="windowActionBarOverlay">true</item>
</style>
-->
<!-- this style is only referenced in a Light.DarkActionBar based theme -->
<style name="Theme.Sri.Widget" parent="#style/Theme.AppCompat">
<item name="popupMenuStyle">#style/PopupMenu</item>
<item name="dropDownListViewStyle">#style/DropDownListView</item>
</style>
</resources>
Please help me. Thank you guys.
The Action Bar Style Generator is very useful, but it generates a lot of files, most of which are irrelevant if you only want to change the background colour please look at this:
https://stackoverflow.com/a/20077381/611258.
Although i strongly urge you to use the new toolbar or its support library equivalent.

How to set theme at runtime in android

I tried to set theme at run time, other than action bar everything works fine.
I am setting theme in oncreate() before super.oncreate(...)
How to set theme in action bar ?
This is my theme in style.xml
<style name="abcThemeTest" parent="Theme.AppCompat.Light">
<item name="android:windowBackground">#color/RED</item>
<item name="actionBarStyle">#style/MyActionBarTest</item>
</style>
<style name="MyActionBarTest" parent="#style/Widget.AppCompat.ActionBar">
<item name="background">#color/RED</item>
<item name="android:background">#color/RED</item>
<item name="titleTextStyle">#style/MyActionBarTitleTextTest</item>
</style>
<style name="MyActionBarTitleTextTest" parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#color/WHITE</item>
<item name="android:textStyle">bold</item>
</style>
Simply Modify your style file like this.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme"
parent="#style/Theme.AppCompat">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="android:actionBarTabTextStyle">#style/MyActionBarTabText</item>
<item name="android:actionMenuTextColor">#color/actionbar_text</item>
<!-- Support library compatibility -->
<item name="actionBarStyle">#style/MyActionBar</item>
<item name="actionBarTabTextStyle">#style/MyActionBarTabText</item>
<item name="actionMenuTextColor">#color/actionbar_text</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar"
parent="#style/Widget.AppCompat.ActionBar">
<item name="android:titleTextStyle">#style/MyActionBarTitleText</item>
<!-- Support library compatibility -->
<item name="titleTextStyle">#style/MyActionBarTitleText</item>
</style>
<!-- ActionBar title text -->
<style name="MyActionBarTitleText"
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>
<!-- ActionBar tabs text -->
<style name="MyActionBarTabText"
parent="#style/Widget.AppCompat.ActionBar.TabText">
<item name="android:textColor">#color/actionbar_text</item>
<!-- The textColor property is backward compatible with the Support Library -->
</style>
</resources>

How do I change the style(color) of tabs in action bar v7 of android ?

I'm trying this to change the color and style of tabs in action bar using the v7 support library. But only the color of action bar is changed not the tabs. Please tell me what I'm doing wrong.
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme"
parent="#style/Theme.AppCompat.Light.DarkActionBar">
<!-- Support library compatibility -->
<item name="actionBarStyle">#style/MyActionBar</item>
<item name="actionBarTabStyle">#style/TabStyle</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar"
parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<!-- Support library compatibility -->
<item name="background">#color/action_bar</item>
</style>
<style name="TabStyle"
parent="#style/Widget.AppCompat.ActionBar.TabView">
<item name="background">#drawable/tab_bar_background</item>
</style>
Try this (if you use actionbar tabs):
<style name="ActionBarTabs" parent="#style/Widget.AppCompat.Light.ActionBar.TabView.Inverse">
<item name="titleTextStyle">#style/ActionBarTitle</item>
<item name="android:titleTextStyle">#style/ActionBarTitle</item>
<item name="background">#drawable/tab_bar_background</item>
<item name="android:background">#drawable/tab_bar_background</item>
</style>
<style name="ActionBarTabBar" parent="#style/Widget.AppCompat.Light.ActionBar.TabBar.Inverse">
<item name="android:showDividers">middle</item>
<item name="android:divider">#drawable/list_divider_holo_light</item>
<item name="android:dividerPadding">8dp</item>
<item name="android:background">#color/actionbar_background</item>
</style>
<style name="TabTextStyle" parent="#style/Widget.AppCompat.ActionBar.TabText">
<item name="android:textColor">#android:color/black</item>
</style>
and in your theme:
<style name="AppTheme" parent="#style/AppBaseTheme">
...
<item name="android:actionBarTabStyle">#style/ActionBarTabs</item>
<item name="actionBarTabStyle">#style/ActionBarTabs</item>
<item name="android:actionBarTabTextStyle">#style/TabTextStyle</item>
<item name="actionBarTabTextStyle">#style/TabTextStyle</item>
<item name="android:actionBarTabBarStyle">#style/ActionBarTabBar</item>
<item name="actionBarTabBarStyle">#style/ActionBarTabBar</item>
...
</style>
If you want to change the color of the menu items in the action bar you have to set the actionMenuTextColor in your theme style.
<style name="PortfolioTheme" parent="android:style/Theme.Holo.Light">
<item name="android:actionMenuTextColor">#24598a</item>
<item name="actionMenuTextColor">#24598a</item>
</style>
To customise tabs color, I suppose you should change your TabStyle item to be :
<item name="android:actionBarTabBarStyle">#style/TabStyle</item>
override "android:actionBarTabBarStyle" rather than "android:actionBarTabStyle"

Categories

Resources