Overriding ActionBarCompat overflow pop-up background? - android

I am using actionbarcompat for my android project and using #style/Theme.AppCompat.Light.DarkActionBar as my base Theme.The overflow menu in this action bar has a black background by default which I want to change to white color.I know this can be done overdding the popup widget with property popupBackground but its not working in my case.My styles file has following code:
<style name="MyTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="android:actionDropDownStyle">#style/MyActionBarDropDown</item>
<item name="android:popupMenuStyle">#style/PopupMenu</item>
</style>
<style name="PopupMenu" parent="#style/Widget.AppCompat.PopupMenu">
<item name="android:popupBackground">#drawable/menu_dropdown_panel_example</item>
<item name="popupBackground">#drawable/menu_dropdown_panel_example</item>
</style>
But the above code is not running as its giving me Error: No resource found that matches the given name: attr 'popupBackground'.SomeOne please help me to correct above code.

Just remove ->
<item name="popupBackground">#drawable/menu_dropdown_panel_example</item>
Put it like this ->
<style name="PopupMenu" parent="#style/Widget.AppCompat.PopupMenu">
<item name="android:popupBackground">#drawable/menu_dropdown_panel_example</item>
</style>

Related

Style showing error in android

The following style shows error in eclipse
<style name="AppTheme" parent="android:style/Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/primary</item>
<item name="colorPrimaryDark">#color/primary</item>
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="drawerArrowStyle">#style/DrawerArrowStyle</item>
<item name="colorControlNormal">#color/primary</item>
<item name="colorControlActivated">#color/primary</item>
<item name="colorControlHighlight">#color/primary</item>
</style>
<style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle">
<item name="spinBars">true</item>
<item name="color">#color/white</item>
</style>
it shows a error like this
error: Error retrieving parent for item: No resource found that matches the given name 'android:style/Theme.AppCompat.Light.NoActionBar'.
while i searched, i get to know that it is the problem of the dependency. I tried a lot to solve it. But i still get the same error .
If i change the theme there is no error, but i need this particular style.
I tried the following theme
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
// Your style here
this is woking . but i need the above theme .
If your activity extends AppCompactActivity, your parent theme should be
<style name="AppBaseTheme" parent="#style/Theme.AppCompat.Light.NoActionBar" />
where as, if using ActionBarActivity, theme should be
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.NoActionBar" />
Make sure you have set up the dependencies in your project. This feature required appcompactv7.

Overflow menu row customization

I am wanting to customise the rows of the overflow menu in the action bar. I found a great blog post explaining how to go about doing this, which seem simple enough. The link is below.
http://scriptedpapers.com/2014/08/12/android-action-bar-overflow-menu-customization/
I am specifically wanting to change the background colour of the overflow menu rows so the theme that I am using looks like the following:
<resources>
<!--the theme applied to the application or activity -->
<style name="CustomActionBarTheme" parent="#android:style/Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/CustomActionBar</item>
<item name="android:homeAsUpIndicator">#drawable/upcaret</item>
<item name="android:actionOverflowButtonStyle">#style/CustomOverflowButton</item>
<item name="android:popupMenuStyle">#style/PopupMenu</item>
</style>
<!--ActionBar style -->
<style name="CustomActionBar" parent="#android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">#color/customBlue</item>
</style>
<style name="CustomOverflowButton" parent="#android:style/Widget.Holo.Light.ActionButton.Overflow">
<item name="android:src">#drawable/overflowbutton</item>
</style>
<style name="PopupMenu" parent="android:Widget.Holo.Light.ListPopupWindow">
<item name="android:popupBackground">#color/customBlue</item>
</style>
Applying this theme to the application, the background colour of the overflow menu remains the same colour as the default for Holo.Light.DarkActionBar, despite setting a custom popupMenuStyle.
For my project, the minSdkVersion is 15 and targetSdkVersion is 19.
Does anyone have any ideas?
Thanks.
Try specifying a 9-patch drawable instead of a color.
Go here and choose the color that you want your rows to be by selecting a color from the "Popup color" drop-down.
The only file you need from the zip is menu_dropdown_panel.9.png.
Make sure to place this file in your various drawable-xxxx folders.
Then use it like this:
<style name="PopupMenu" parent="android:Widget.Holo.Light.ListPopupWindow">
<item name="android:popupBackground">#drawable/menu_dropdown_panel</item>
</style>
If it still doesn't work, add this to the above:
Add this line to your main theme (CustomActionBarTheme):
<item name="android:actionBarWidgetTheme">#style/PopupWrapper</item>
Then add this:
<style name="PopupWrapper" parent="#android:style/Theme.Holo">
<item name="android:popupMenuStyle">#style/PopupMenu</item>
</style>

Lollipop Theme issue

I am using sherlock action bar in my project, I have used Theme.Sherlock.Light.DarkActionBar
<style name="AppTheme" parent="Theme.Sherlock.Light.DarkActionBar">
<item name="android:homeAsUpIndicator">#drawable/transparent</item>
<item name="homeAsUpIndicator">#drawable/transparent</item>
<item name="actionBarStyle">#style/Widget.MyTheme.ActionBar</item>
<item name="android:actionBarStyle">#style/Widget.MyTheme.ActionBar</item>
<item name="android:titleTextStyle">#style/Widget.MyTheme.TitleTextStyle</item>
<item name="android:textAllCaps">false</item>
</style>
Problem :
I am getting light color menu with lollipop:
pre lollipop image :
Lollipop image :
can some one guide me, how can I get slimier menu color on both .
You can create a style which extends from actionbar sherlock to change color of you actionbar with other properties.
<style name="Theme.MyTheme" parent="Theme.Sherlock.ForceOverflow">
<item name="actionBarStyle">#style/Widget.MyTheme.ActionBar</item>
<item name="android:actionBarStyle">#style/Widget.MyTheme.ActionBar</item>
</style>
<style name="Widget.MyTheme.ActionBar" parent="Widget.Sherlock.ActionBar">
<item name="android:background">#ff000000</item>
<item name="background">#ff000000</item>
<item name="android:textColor">#CC3232</item>
</style>
For TextColor only
<style name="YOURTHEME.ActionBar.TitleTextStyle" parent="TextAppearance.Sherlock.Widget.ActionBar.Title">
<item name="android:textColor">#color/yourColor</item>
<item name="textColor">#color/yourColor</item>
</style>
Last resort Solution
<item name="android:textColorPrimary">#color/yourColor</item>
You should create a new styles.xml in a separate values-21 folder. There, you can define a specific theme/style that suits your needs for Lollipop devices only.
You should be using the ActionBar or ToolBar provided by app-compat library, instead of ActionBarSherlock.
ABS uses replacement Holo themes for older versions, which I guess hasn't been updated in a while.

Error: No resource found that matches the given name: attr 'abBackground'

I'm using ActionBarSherlock, and want to use a custom background for both the ActionBar and the content view below it. When I try this, the background fills the whole screen, including the actionbar:
<style name="MyTheme" parent="#style/Theme.Sherlock">
<item name="android:windowBackground">#drawable/background</item>
</style>
So, from this answer, I tried to add abBackground to the theme:
<style name="MyTheme" parent="#style/Theme.Sherlock">
<item name="android:windowBackground">#drawable/background</item>
<item name="abBackground">#drawable/bg_button_idle</item>
</style>
However, I get the error
Error: No resource found that matches the given name: attr 'abBackground'.
Why is this, and how can I fix it?
Here's how you can change the actionbar background:
<style name="MyTheme" parent="Theme.Sherlock">
<item name="actionBarStyle">#style/MyActionBar</item>
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="Widget.Sherlock.ActionBar">
<item name="background">#drawable/your_custom_drawable</item>
<item name="android:background">#drawable/your_custom_drawable</item>
</style>
//there is no abBackground
<item name="abBackground">#drawable/bg_button_idle</item>
//try
<item name="android:background">#drawable/bg_button_idle</item>
if the project is a library module you shou check the Library module

Style Inheritance with ActionBar Tab troubles

Many of my questions about "styling" actionbar tabs were answered by adamp in this thread on tab style, but I am still struggling with my arriving at the desired presentation.
Specifically, I am attempting to do what adamp suggested in the following fragment from my styles.xml file, but, I cannot get the inherited (Widget.holo.actionbar) feature of a light blue line to appear under the selected tab nor is there any indication of selection:
<style name="MyTheme" parent="android:style/Theme.Holo">
<item name="android:actionBarStyle">#style/CustomActionBar</item>
</style>
<style name="CustomActionBar" parent="android:style/Widget.Holo.ActionBar">
<item name="android:actionBarTabTextStyle">#style/customActionBarTabTextStyle</item>
<item name="android:actionBarTabStyle">#style/customActionBarTabStyle</item>
<item name="android:actionBarTabBarStyle">#style/customActionBarTabBarStyle</item>
</style>
<style name="customActionBarTabTextStyle" parent="#style/CustomActionBar">
<item name="android:textColor">#2966c2</item>
<item name="android:textSize">20sp</item>
<item name="android:typeface">sans</item>
</style>
<style name="customActionBarTabStyle" parent="#style/CustomActionBar">
<!-- <item name="android:background">#drawable/actionbar_tab_bg</item> -->
<item name="android:paddingLeft">20dp</item>
<item name="android:paddingRight">20dp</item>
</style>
<style name="customActionBarTabBarStyle" parent="#style/CustomActionBar">
<item name="android:paddingLeft">240dp</item>
</style>
Can someone explain why the thin blue line selection behavior of the Honeycomb Gallery Sample App does not work for me?
New insight since this was written: the problem here, I think, is that the style I have created to overide ActionBarTabStyle is entirely bogus:
<style name="customActionBarTabStyle" parent="#style/CustomActionBar">
<item name="android:paddingLeft">20dp</item>
<item name="android:paddingRight">20dp</item>
</style>
I need to specify the correct parent of this style per "Theme.holo"....how can one find where the default style is so it can be specified as a parent?
Thanks
To specify the correct parents for actionbar style in API 11, Check doc here:
https://developer.android.com/training/basics/actionbar/styling.html

Categories

Resources