SupportActionMode background color with material design - android

I'm using Toolbar as setSupportActionBar(toolbar). How i can change action mode background color. I try in my App Theme change attribute:
<item name="android:actionModeBackground">#color/color</item>
But it is not working. How can I solve this problem?

The AppCompat library supports versions of Android that don't have ActionBars, so it needs to define attributes to use that wouldn't exist on those devices. You want to use this:
<item name="actionModeBackground">#color/color</item>
The same goes for any other style/theme attributes you want to use that have been backported. But you'd use platform ones that exist, like android:textColor or android:background.

Related

Tint Navigation Icon in Toolbar

How to tint menu icons is already covered a few times, like here:
Toolbar icon tinting on Android
Additionally to this solution there is still the problem of the navigation icon.
Applying a Theme(Overlay) to your Toolbar just tints the text and the whitelisted icons (see: https://stackoverflow.com/a/26817918/2417724)
If you set a custom icon (which happens to be quite easy the case, as you need to change it if you don't want to display the default back arrow) then this custom icon does not get tinted.
How do you handle your Icons then?
All my icons are per default black and I don't want to have special white versions just to use them in the Toolbar then.
The appcompat navigation button - which is simply an AppCompatImageButton - can be styled through the toolbarNavigationButtonStyle attribute. The default style for that in the AppCompat themes is Widget.AppCompat.Toolbar.Button.Navigation, and we can extend that style to add a tint attribute value. For example:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
...
<item name="toolbarNavigationButtonStyle">#style/Toolbar.Button.Navigation.Tinted</item>
</style>
<style name="Toolbar.Button.Navigation.Tinted" parent="Widget.AppCompat.Toolbar.Button.Navigation">
<item name="tint">#color/nav_button_tint</item>
</style>
There are a couple of caveats to be aware of when using this method.
Prior to support library version 25.4.0, AppCompatImageButton did not offer its own tint attribute, and therefore a tint attribute in the app's namespace will not apply (and just won't exist, unless defined elsewhere). It is necessary to use the platform android:tint attribute if using support library version 25.3.0 or earlier.
Unfortunately, this leads to another catch, in that the platform tint prior to Lollipop (API level 21) can handle only simple, single color values, and using a ColorStateList (<selector>) resource value will cause an Exception to be thrown. This poses no problems if the android:tint value is a simple color, but it is often desired to tint the navigation icon to match another theme color attribute, which may very well be a ColorStateList. In this case, it would be necessary to create separate styles in res/values/ and res/values-21/, specifying a simple color value for android:tint in res/values/.
For example, if tinting to match the theme's primary text color:
res/values/styles.xml
<item name="android:tint">#color/normal_text_color</item>
res/values-v21/styles.xml
<item name="android:tint">?android:textColorPrimary</item>
You need only concern yourself with the notes above if you're stuck using a support library version less than 25.4.0.
To effectively set the tint color of the navigation icon programmatically you need to set the drawable first and apply the tint afterwards.
toolbar.setNavigationIcon(R.drawable.ic_back)
toolbar.children.forEach {
(it as? AppCompatImageButton)?.imageTintList =
ColorStateList.valueOf(Color.GREEN)
it.refreshDrawableState()
}

Android define custom style for Menu item

I want to customize text style Android menu item.
I put this to styles.xml
<item name="android:actionMenuTextAppearance">#style/my_custome_actionbar_menu_item</item>
It does not work, but when I remove "android:", it work properly
<item name="actionMenuTextAppearance">#style/my_custome_actionbar_menu_item </item>
Do you know What is different between having "android: " and not?
if you use api7-13,use actionMenuTextAppearance,and if your sdk api>17,use android:actionMenuTextAppearance,maybe the sdk you are using is lower than 17.
I figure out the reason about AppCompat
With new AppCompat-v7 (v21) ActionBar style's properties need to refer to the app namespace, that is without android: prefix.
So,for retro-compatibility, we should use actionBarStyle along with android:actionBarStyle:

Android AppCompat 22.1.1 default text color and ActionMode style

I am updating my application to use the version 22.1.1 of the Android Support Library. My application theme inherits from Theme.AppCompat.Light.DarkActionBar.
It works fine, except that all texts are white if the TextView style is set to one of the predefined style. So I end up with white texts on light background (default background color). With version 22.0.0, I had no issue.
I tried the follow in my theme, but it does not seem to work:
<item name="android:textColor">#color/black</item>
<item name="android:textColorPrimary">#color/black</item>
<item name="android:textColorPrimaryInverse">#color/black</item>
Moreover, the ActionMode now has a black background instead of white, as it used to be with 22.0.0.
Any idea on how to change this?
I was using the theme attribute in my theme to set the Toolbar theme. That's a mistake. The Toolbar theme has to be defined on the Toolbar tag directly.
For the ActionMode background color, it looks like I was taking profit of a bug without knowing it.

Modify android theme from appcompat theme

Is there any way to change an attribute from the stock android themes, if the App is using the AppCompat theme?
My Problem:
I am using AppCompat theme in order to get the L-Look.
But I need to use the ActionMode, which is from basic Android API.
If I change the ActionMode style within my AppCompat theme, the style for the SupportedActionMode is applied.
But i defintily need the basic API ActionMode.
Does anybody know a way how to do this, in order to style my ActionMode background?
Use ActionMode properties' names without android: prefix.

Material design : coloring two buttons with two colors in Android

I've looked around for a proper way of handling the background color of Buttons in android 5.0 and the only solution I could find was to define a style for the Button in values-21/styles.xml :
<item name="android:colorButtonNormal">#2196f3</item>
Is this the only way of coloring a button, while preserving both its design and the ripple effect ?
If yes, It would imply that I have to define a custom theme for each Button which has a different color, really ???
N.B : My question doesn't relate to backwards compatibility and AppCompat, which has already been discussed a lot.
You can use the tint option to change coloring that way, instead of making a seperate theme for each button, you would just have each tinted a different color. See here: Material Design Drawables
Yes, you have to define a separate theme with colorButtonNormal for each color. You can set theme to your Button as following:
<style name="ColorButonButton" parent="Theme.AppCompat.Light">
<item name="colorButtonNormal">#color/newColor</item>
</style>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Text"
android:theme="#style/ColorButonButton"/>

Categories

Resources