The options menu has a translucent background and I would like to make it solid and non-transparent. Is there a way?
Try this:
<style name="MyTheme" parent="android:Theme">
<item name="android:panelFullBackground">{your color or drawable}</item>
</style>
Also, see:
http://code.google.com/p/android/issues/detail?id=4441
How to change the background color of the options menu?
Completely overriding menu panel: Android MenuItem Toggle Button
set android:theme="myTheme", and define your own theme with whatever colours you want. Read up about Styles, and look at the android themes.xml.
Try this for android 4.0:
<style name="MyTheme" parent="#android:style/Theme.DeviceDefault">
<item name="android:popupMenuStyle">#style/MyPopupMenu</item>
</style>
<style name="MyPopupMenu" parent="#android:style/Widget.DeviceDefault.ListPopupWindow">
<item name="android:popupBackground">{your color or drawable}</item>
</style>
Also, the following site generate Action Bar Style :
http://jgilfelt.github.com/android-actionbarstylegenerator/
If you don't want to style a whole theme and just change the options menu background then set the panelFullBackground property to a DRAWABLE RESOURCE of your liking. Setting it to a color directly doesn't work so either make one coloured - 9patch, if you want to save in size -image and set it to that or make a couple and make a selector drawable with an image for each state.
I put my definition in a style that i use for all the activities in my project using:
#drawable/optionsmenu_back
optionsmenu_back being a 9patch image with a solid colour...
Related
I want to change a spinner's dropdown menu background color without changing the background color of the spinner itself (it's transparent). Is it possible?
Yep, it's possible. Use android:popupBackground on the Spinner in your XML or setPopupBackgroundResource(int) in code.
To change the background color of the drop-down list, add android:colorBackground parameter to the theme in your styles.xml
Code:
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="android:colorBackground">#ff0000</item>
</style>
Thus, the overall style is preserved: the effect when pressed, rounded corners, etc.
Screenshot:
When using Material Design 3 responsible attribute is:
<item name="colorSurface">#color/foo</item>
In my TextView I enabled text-selection with android:textIsSelectable.
The problem is, that the appearing actionbar is white and the color of the buttons (copy , select, etc.) is white too. (I use actionbarsherlock 4.4.0)
Is there a possibility to change the color of these items in the styles.xml and if yes: What is the correct way?
Edit:
I found out that i can customize the ActionMode Tab using:
<style name="MyCustomTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionModeBackground">#color/color1</item>
<item name="android:actionModeSplitBackground">#color/color1</item>
</style>
But i am not able to change the color of the buttons
I am using AutoCompleteTextView in my android application. I am using Theme.Light as my default theme for my application.
Here is how my AutoCompleteTextView look like
Now, I want to change the BLUE color border of that AutoCompleteTextView to some other color ,for different selection, keeping the border style as it as. I dont want full border. How to do that?
You can try like this..
see http://www.androidworks.com/changing-the-android-edittext-ui-widget for details
For other theme implementation go for this way
In your manifest in application
android:theme="#style/firsttheme"
IN res/values you can define theme.xml
<resources>
<style name="firsttheme" parent="#android:style/Theme" >
<item name="android:_DEFAULT_BASE_COLOR_1">#XXXXXX</item>
<item name="android:windowNoTitle">true</item>
... .
</style>
</resources>
For more info theme
You can use Holo Colors to tint it. It generates the 9-patchs and the styles.
The application I've been developing uses ActionBarSherlock, and the main theme inherits from Theme.Sherlock.Light.DarkActionBar. The design requires that the overflow menu popups have a dark coloured background and white text. This works fine for devices without a physical menu button, and the text appears white as intended. However, if the device DOES have a physical menu button, the text shown in the menu displayed remains black.
My main theme contains
<item name="android:panelBackground">#drawable/menu_hardkey_panel</item>
...Where #drawable/menu_hardkey_panel is a dark coloured 9patch.
The resulting appearance of the menu popup is...
I'm unable to determine why this is happening, or how to manually change the colour of the text. In my main theme, I've tried all of the following...
<item name="android:actionMenuTextColor">#android:color/white</item>
<item name="android:textAppearanceLargePopupMenu">#style/MyMenuTextAppearance.Large</item>
<item name="android:textAppearanceSmallPopupMenu">#style/MyMenuTextAppearance.Small</item>
I've even tried
<item name="android:actionBarWidgetTheme">#style/Theme.MyApp.Dark</item>
...Where Theme.MyApp.Dark is...
<style name="Theme.MyApp.Dark" parent="#style/Theme.Sherlock">
<item name="android:dropDownListViewStyle">#style/DropDownListView</item>
<item name="dropDownListViewStyle">#style/DropDownListView</item>
</style>
None have let me change the text to white. If I make my base theme inherit from Theme.Sherlock, the problem is solved and the text is white, but unfortunately that's not an option.
Not entirely sure about this, but I believe the pop-up menu uses the same styling as the overflow menu. In which case you'd just do something like this.
<item name="android:itemTextAppearance">#style/your_new_text_appearance</item>
<style name="your_new_text_appearance">
<item name="android:textColor">#android:color/white</item>
</style>
Giving it a chance: there is a text appearance called actionMenuTextAppearance. Have you tried that?
Update: I did some more digging and I believe that this file is the layout And there they refer to textAppearanceListItemSmall and textAppearanceSmall. However, it takes this value from a special theme which is specified as following in Theme.Holo.Light
<item name="panelMenuListTheme">#android:style/Theme.Holo.Light.CompactMenu</item>
And like this in Theme.Holo:
<item name="panelMenuListTheme">#android:style/Theme.Holo.CompactMenu</item>
The problems comes from the fact that the parent of Sherlock.__Theme.DarkActionBar is Theme.Sherlock.Light. This is not valid for the dark action bar. Taking the line from Theme.Holo should do the trick.
In my research I haven't found a way to change the text color, but you can at least handle hardkey menus gracefully.
This link provided me with a passable solution to the problem:
https://github.com/jgilfelt/android-actionbarstylegenerator/issues/30
Commenting out the "android:panelBackground" item from my generated theme allowed the text to at least be visible on hardkey menus, even if it doesn't perfectly match the theme.
You could also try replacing the "menu_hardkey_panel_whatever.9.png" drawable with something that will work for your theme and the black text.
For me this solves the problem, try this instead:
<style name="MyTheme" parent="Theme.Sherlock.Light.DarkActionBar">
...
<item name="actionBarWidgetTheme">#null</item>
<item name="android:actionBarWidgetTheme">#null</item>
...
</style>
I found the solution, use:
getSupportActionBarContext()
e.g.
ArrayAdapter<CharSequence> list =
ArrayAdapter.createFromResource(getSupportActionBarContext(), R.array.navigation, layout.simple_spinner_item);
list.setDropDownViewResource(layout.simple_spinner_dropdown_item);
getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
getSupportActionBar().setListNavigationCallbacks(list, this);
I think that due to the fact that Theme.Sherlock.Light.DarkActionBar don't style its contents right is due to the actionWidgetTheme attribute is used with a ContextThemeWrapper for inflating the action bar views (Jake Wharton's own words), thus something like the following (not tested) will be needed to fulfill your needs, though breaking your need of not using Theme.Sherlock as parent in one way:
<style name="MyColorTheme" parent="Theme.Sherlock">
<item name="android:actionMenuTextColor">#android:color/white</item>
<item name="actionMenuTextColor">#android:color/white</item>
</style>
<style name="YourMainTheme" parent="Theme.Sherlock.Light.DarkActionBar">
<item name="android:actionMenuTextAppearance">#style/MyColorTheme</item>
<item name="actionMenuTextAppearance">#style/MyColorTheme</item>
</style>
Might work or not work. That's the question :)
I'm trying to implement ActionBarSherlock because I was told it is relatively easy to implement and customize. I've found it was pretty easy to implement, but I'm trying to change the background color of the ActionBar and it's proving difficult.
According to the the site (link), it seems you can inherit one of the ActionBarSherlock's themes and then override the properties you need.
This is what I have so far:
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<style name="Theme.ActionBar" parent="Theme.Sherlock.ForceOverflow">
<item name="android:background">#000000</item>
<item name="background">#000000</item>
</style>
</resources>
I'm noticing the built-in theme are using images for the background, but I'm praying I don't have to create images to change the background color.
Thanks.
The action bar background color is defined in a style for the action bar, not in the theme itself. You'll need to do something like this:
<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>
</style>
Be careful using colors defined in XML. ColorDrawable did not respect it's view bounds on pre-Honeycomb so if you use tab navigation with a separate background for the stacked tab view you will have problems.
I just used
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#00853c")));
It changed the background color. Hope it helps.
The code mentioned by Jake Wharton is true. But when applying the code to the styles.xml may not work if you have minSDK<11 because android:actionBarStyle is supported in API-11+
To solve that error:
Make a folder of values-v11 in your res folder and create the XML file as mentioned above.