Transparent Overlay ActionBar with AppCompat? - android

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>

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>

DarkActionBar on pre lollipop doesn't have white icons

I think i've tried everything on the Internet but nothing seems to work. The icons always stay gray but I want them white. Isn't that purpose of DarkActionBar?
<style name="AppTheme"
parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/one</item>
What it looks like on 4.4 and on 5.0. I want the 5.0 look.
Here is what I have in my project, it works just fine:
<style name="CustomActionBarTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="actionBarStyle">#style/MyActionBar</item>
<item name="android:windowContentOverlay">#null</item>
<item name="drawerArrowStyle">#style/DrawerArrowStyle</item>
<item name="android:fastScrollThumbDrawable">#drawable/scroller_style</item>
<item name="colorPrimary">#color/statbar_bg</item>
<item name="colorPrimaryDark">#color/statbar_bg</item>
<item name="colorAccent">#color/statbar_bg</item>
<!-- <item name="windowActionBarOverlay">true</item> -->
</style>
<style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle">
<item name="spinBars">true</item>
<item name="color">#android:color/white</item>
</style>
<!-- Overflow menu -->
<!-- ActionBar styles -->
<style name="MyActionBar" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#color/actionbar_bg</item>
<item name="background">#color/actionbar_bg</item>
<item name="elevation">0dp</item>
<item name="android:titleTextStyle">#style/MyTheme.ActionBar.TitleTextStyle</item>
</style>
<style name="MyTheme.ActionBar.TitleTextStyle" parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#FFFFFF</item>
</style>
<style name="MyActionButtonStyle" parent="#android:style/Widget.ActionButton">
<item name="android:minWidth">0dip</item>
<item name="android:paddingLeft">0dip</item>
<item name="android:paddingRight">0dip</item>
</style>
I would also suggest you to check for different style/theme files in different values folders, maybe something is overriding.

Android action bar autosrollable title

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?

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.

remove native ActionBar highlight of select

i want to remove default highlight of item selection in Android ActionBar, im using AppCompat
i try to set android:selectableItemBackground to transparent by seting color, or transparent shape or event drawable transparent png but no success
<style name="NActionBar" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:displayOptions">showHome|homeAsUp|showTitle</item>
<item name="displayOptions">showHome|homeAsUp|showTitle</item>
<item name="android:icon">#android:color/transparent</item>
<item name="android:titleTextStyle">#android:color/white</item>
<item name="android:selectableItemBackground">#android:color/transparent</item>
<item name="android:background">#drawable/ab_transparent_example</item>
</style>
[EDIT]
style.xml
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
<style name="NTheme" parent="AppBaseTheme">
<item name="android:windowContentOverlay">#null</item>
<item name="android:buttonStyle">#style/NButton</item>
<item name="android:editTextStyle">#style/NEditText</item>
<item name="android:actionBarStyle">#style/NActionBar</item>
</style>
<style name="NThemeNoActionBar" parent="NTheme">
<item name="android:windowActionBar">false</item>
</style>
<style name="NButton" parent="android:style/Widget.Button">
<item name="android:background">#drawable/big_button</item>
<item name="android:textColor">#android:color/white</item>
</style>
<style name="NSmallButton" parent="android:style/Widget.Button">
<item name="android:background">#drawable/small_button</item>
<item name="android:textColor">#android:color/white</item>
<item name="android:textSize">10sp</item>
</style>
<style name="NEditText" parent="android:style/Widget.EditText">
<item name="android:background">#android:color/transparent</item>
<item name="android:textColor">#color/blue</item>
<item name="android:textColorHint">#color/blue</item>
</style>
<!-- ActionBar styles -->
<style name="NActionBar" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:displayOptions">showHome|homeAsUp|showTitle</item>
<item name="displayOptions">showHome|homeAsUp|showTitle</item>
<item name="android:icon">#android:color/transparent</item>
<item name="android:titleTextStyle">#android:color/white</item>
<item name="android:selectableItemBackground">#android:color/transparent</item>
<item name="android:background">#drawable/ab_transparent_example</item>
</style>
<style name="FullscreenTheme" parent="android:Theme.NoTitleBar">
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowBackground">#null</item>
<item name="metaButtonBarStyle">#style/ButtonBar</item>
<item name="metaButtonBarButtonStyle">#style/ButtonBarButton</item>
</style>
<style name="ButtonBar">
<item name="android:paddingLeft">2dp</item>
<item name="android:paddingTop">5dp</item>
<item name="android:paddingRight">2dp</item>
<item name="android:paddingBottom">0dp</item>
<item name="android:background">#android:drawable/bottom_bar</item>
</style>
<style name="ButtonBarButton" />
<style name="FullHeightDialog" parent="android:style/Theme.Dialog">
<item name="android:windowNoTitle">true</item>
<item name="android:windowFrame">#null</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowBackground">#android:color/transparent</item>
</style>
The actionBarItemBackground theme attribute will allow you to change the action item selector.
If you're using it with ActionBarSherlock or ActionBarCompat, be sure to provide an entry with and without the android: prefix.
In your style you can use below lines:
<item name="android:actionBarItemBackground">#drawable/my_drawable</item>
<item name="actionBarItemBackground">#drawable/my_drawable</item>
Hope it will help you..

Categories

Resources