Android actionbar customize menuitem background - android

I have a menu in my android activity (I am working with Xamarin.Android) and that contains several items, like this one:
<item android:id="#+id/menuitem1"
android:icon="#drawable/ic_action_share"
android:showAsAction="ifRoom" />
I can customize the whole ActionBar. But I want to customize just one item in the actionbar. Like the following Icon in the middle (the blue one):
How can I achive this? Thanks in advance.

First thing that we need to do is set up the basic colour values in res/values/colors.xml that we used in Jeff’s Generator tool:
<color name="sa_green">#14a804</color>
<color name="stacked_green">#118504</color>
<color name="accent_green">#97e08f</color>
create a new style, which we’ll call “ActionBar” in res/values/styles.xml:
<style name="ActionBar" parent="#android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">#color/sa_green</item>
<item name="android:backgroundStacked">#color/stacked_green</item>
<item name="android:backgroundSplit">#color/sa_green</item>
</style>
Now it must set this style on the ActionBar by adding an actionBarStyle to the theme in res/values/styles.xml:
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/ActionBar</item>
</style>
.
.
.
try this ...

Related

How to change CAB style in Android?

I'm trying to change the Contextual Action Bar style using this snippet
<style name="AppTheme.Reader" parent="AppTheme">
<item name="android:actionModeStyle">#style/AppTheme.ActionMode</item>
<item name="actionModeStyle">#style/AppTheme.ActionMode</item>
</style>
<style name="AppTheme.ActionMode" parent="Widget.AppCompat.ActionMode">
<item name="background">#color/white</item>
<item name="titleTextStyle">#style/AppTheme.ActionMode.Title</item>
<item name="subtitleTextStyle">#style/TextAppearance.AppCompat.Widget.ActionMode.Subtitle</item>
</style>
And setting the theme in the right activity
android:theme="#style/AppTheme.Reader"
Then I've used a
TextView.setCustomSelectionActionModeCallback()
To intercept the selected text, but when it comes up the CAB it has the default style and seems that my custom hasn't been applied.
Where am I wrong?
Try to use the latest support lib (as of now: v23.4.0). Depends where your parent "AppTheme" inherits from, it may or may not work but if you try to inherit from the "AppCompat" theme the following should work and once you see the white background you can fill in the rest of the attributes:
<style name="AppTheme" parent="Theme.AppCompat">
<item name="actionModeStyle">#style/ActionModeTheme</item>
</style>
<style name="ActionModeTheme" parent="#style/Widget.AppCompat.ActionMode">
<item name="background">#color/white</item>
</style>
Of course assuming <color name="white">#fff</color> is defined in colors.xml

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>

android: How to change ListPreference title colour?

I would like to change the title and line color of my ListPreference from blue to pink, to match the line of my action bar.
Any ideas? Thanks in advance!
I've been looking through Android's themes.xml and styles.xml looking at things like dialogPreferenceStyle, but haven't figured it out yet.
Had the same problem today.
Old thread, but I found this: and it works perfectly.
Simply modify your styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<!-- Add this -->
<item name="android:dialogTheme">#style/DialogStyle</item>
<item name="android:alertDialogTheme">#style/DialogStyle</item>
</style>
<!-- Customize your color here -->
<style name="DialogStyle" parent="android:Theme.Material.Dialog">
<item name="android:colorAccent">#color/colorAccent</item>
</style>
Ended up creating a custom ListPreference widget, following this answer.
I hoped to be able to simply change the style without having to implement a custom widget, but I haven't figured that out yet.

Android custom theme

Hello I'm making a custom theme for my app. I want to have a custom ActionBar and background for the rest of the app (below the ActionBar). I'm wondering how to do the background. Right now I have:
<style name="MyTheme" parent="android:Theme.Holo">
<item name="android:actionBarStyle">#style/dActionBar</item>
</style>
<style name="dActionBar" parent="#android:style/Widget.Holo.ActionBar">
<item name="android:background">#4C721D</item>
<item name="android:textColor">#FFFFFF</item>
</style>
Would I just have to do <item name-"android:background"></item> in MyTheme or would I have to create another style? After I create this do I need to put it in the res/styles folder? Also what are the API restrictions on this, if any?
Don't forget to apply your theme to your application in your AndroidManifest.xml.
<application android:theme="#style/CustomActivityTheme" ... />
You can find all the information about styling the Actionbar here.
To style your ActionBar with a nice Holo-look, try this website
Hope this helps!
Try to use below code in your Style.xml file
<resources>
<style name="Theme.Sample" parent="Theme.AppCompat">
<item name="android:colorBackground">#color/primary_material_dark</item>
<item name="actionBarTheme">#color/colorGray</item>
</style>
</resources>
Just need to use android:colorBackground as a name of item to define the background color like as below:
<item name="android:colorBackground">#color/primary_material_dark</item>
Hope you get your answer,Thanks.

Change Theme.Dialog to look like Theme.Light.Dialog in Android

There is no Theme.Light.Dialog to use with the rest of my project that is using Theme.Light.
How can I change Theme.Dialog to look like a Theme.Light version of Dialog.
I know that I must overwrite sections of Theme.Dialog in styles.xml as below. What items should I overwrite with which values?
<style name="dialog_light" parent="#android:style/Theme.Dialog">
<item name="android:???????"></item>
<item name="android:???????"></item>
</style>
I could just make the background that light white grey, but the buttons, spinners etc are also different on the light theme to look better on the light background.
EDIT
Looks like I got it working.
<color name="black">#FF000000</color>
<color name="whitegrey">#FFF2F2F2</color>
<style name="dialog_light" parent="#android:style/Theme.Dialog">
<item name="#android:windowBackground">#color/whitegrey</item>
<item name="#android:textColor">#color/black</item>
</style>
Looks like I got it working.
<color name="black">#FF000000</color>
<color name="whitegrey">#FFF2F2F2</color>
<style name="dialog_light" parent="#android:style/Theme.Dialog">
<item name="#android:windowBackground">#color/whitegrey</item>
<item name="#android:textColor">#color/black</item>
</style>
Further to the above, to avoid making up colors, I did this:
<!-- Makes a "light" equivalent of Theme.Dialog -->
<style name="dialog_light" parent="#android:style/Theme.Dialog">
<item name="#android:background">#android:color/background_light</item>
<item name="#android:textColor">#android:color/primary_text_light</item>
</style>
This is good, thanks!
I just changed it a bit: when I run what you suggested, the entire screen is painted with the back color and the dialog does not look as it should (with the previous activity dimmed).
So instead of using
#android:windowBackground
just use
#android:background

Categories

Resources