Android ActionMode styling, cannot set menu item colour - android

I am trying to set the text colour for all the text inside a ActionMode in android. I have found ways to change TitleTextColor and SubTitleTextColor but I cannot find a way to style the actual non-collapsed menu item text color.
I am using the android.support.v7.widget.toolbar using the statSupportActionMode(ActionMode.Callback) to display the action mode.
Thanks in advance,
Thomas.

<style name="ThemeName" parent="#style/Theme.Sherlock.Light">
<item name="actionMenuTextColor">#color/white</item>
<item name="android:actionMenuTextColor">#color/white</item>
</style>

I used the iconTint attribute to style the menu items. Grab the xml file you use to inflate the menu then add the following attribute for each menu items that you want to style.
android:iconTint="#fff"
The above line of code will render the icons white. It's better to use your theme's color in styling.

Related

How to change to text colour of the Cut/Copy/Paste popup menu

I have the following in my styles.xml
<style name="dialog_style" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="colorAccent">#ffaaaa00</item>
<item name="android:background">#ff444400</item>
<item name="android:textColorPrimary">#ffa25600</item>
</style>
(The horrible colours are for testing only!)
This gives the following
What I want is a dark/black background but when I do that, the text is unreadable.
Q: How do I change the text colour of "Cut", "Copy"...?
tia,
Kevin
I think it's a little bit better solution than user3247782's,
<style name="CustomAlertDialog" parent="Theme.AppCompat.Light.Dialog.Alert">
...
<item name="android:popupBackground">#android:color/transparent</item>
</style>
You can change them by following style names:
<item name="colorAccent">#color/twoCuteSelectionHandlersColor</item>
<item name="android:textColorHighlight">#color/selectionColor</item>
Also you can set highlight color directly for pacific EditText using android:textColorHighlight attribute in xml layout or programmatically:
et.setHighlightColor(color);
For context menu you need create your own context menu. check this question for how disabling default context menu and implementing custom menu.
This isn't really an answer. The black-on-black edit menu is only generated from an EditText contained in an AlertDialog. The same code in a Fragment gives black-on-white.
So I "solved" my problem by converting the AlertDialog into a Fragment.
The original question, though, is still unanswered.
Alert Dialog and Popup Menu generaly take the color of #ColorAccent as the background. So try changing the colorAccent or just inflate a custom xml with the specifications you want.
Just change the parent of it from Theme.Material.Light to Theme.Material .
It will make the text white, there.
I fixed it by setting a background color with opacity in the style of the alertdialog
In styles.xml
<style name="AppCompatAlertDialogStyle">
...
<item name="android:background">#color/black_overlay</item>
...
</style>
In colors.xml
<color name="black_overlay">#66000000</color>
If you use MaterialAlertDialogBuilder then you can define background color through colorSurface attribute.
Then in styles you can just set background to transparent.
android:background="#android:color/transparent"
Dialog will use the one define in colorSurface and "copy/paste" will use default system colors (e.g. white).

How to change Background color of menuItem in android?

I am working on programmatically add a menu-Item into menu. I want to add background color on selection to particular Item. How can I add background to menuItem?
Your answer would be appreciated.
While other answers provide change style (which will affect all menu items, and, as I understand, need is to change one menu item),I propose you to use android:actionLayout attribute to implement your custom layour for menu item.
See documentation for it (search actionLayout there, it's very simple actually).
Also I think there is a possibility to make a selector as your layout and use it.
Update. Sorry, I mislead you :(
All of this will work only if MenuItem is shown as Action (not when pressing on three dots).
Seems like guys given other answers were right - the only way to customize this is changing themes.
But please check this and this - it might help you to provide selector for your purpose.
Also you can create PopupMenu or even PopupWindow, last one is fully customizable.
The last option is to create custom Spinner, check this.
Hope something from this will help you. Thanks.
Firstly You need to create an Style for popmenu as you want refer below sample for that
<style name="MyApp.PopupMenu" parent="android:Widget.Holo.Light.ListPopupWindow">
<item name="android:textStyle">#style/commonEditTextTheme</item>
<item name="android:popupBackground">#drawable/pop_up_menu_bg_with_shadow</item>
</style>
Place of drawable you can also replace with color as you needed or make XML Drawable into your drawable folder
<style name="commonEditTextTheme" parent="#android:style/TextAppearance.Medium">
<item name="android:fontFamily">sans-serif-light</item>
</style>
this pop menu theme add in your main application or activity theme like below
<!--My Theme-->
<style name="MyTheme" parent="#android:style/Theme.Holo.Light">
......
<item name="android:popupMenuStyle">#style/MyApp.PopupMenu</item>
</style>

MultiAutoCompleteTextView suggestion separator color

I'm using MultiAutoCompleteTextView in my Android app. I need to customize the suggestion list of this control. I've tried this to customize the list separator color but this didn't worked for me. How can I update the default list divider color of MultiAutoCompleteTextView?
In addition to setting the divider color, you need to also set the dividerHeight property or it won't work. And the Popup used by the MultiAutoCompleteTextView is actually a ListView, so setting that is correct here.
Add this to your styles.xml file:
<style name="myStyle" parent="#android:style/THeme.Holo.Light"> <!-- or whatever style you inherit -->
<item name="android:dropDownListViewStyle">#style/DropDownListViewStyle</item>
</style>
<style name="DropDownListViewStyle" parent="android:style/Widget.ListView.DropDown">
<item name="android:divider">#android:color/holo_orange_dark</item>
<item name="android:dividerHeight">2px</item>
</style>
This will set the dividers in the MultiAutoCompleteTextView's Popup to orange.
You can set the divider color of the ListView showing your results. This is set with the divider attribute.
Like this: android:divider="#color/mycolor
As an alternative, you could also create a custom drawable using a ShapeDrawable, that contains it's own custom divider color, then you apply that drawable as the background to your list element.

What property controls Spinner dropdown background?

I have a custom theme created with this generator. It has a custom style for Spinners which I don't like. I want to change the background drawable but I can't seem to figure out which property controls this.
This is what the themed version looks like
And here is what it will look like when using the Holo.Light theme.
Notice the dark gray lines around the dropdown list in the first (themed) image. This is what I want to get rid of. What property controls this? I want them to match the default.
Also, what controls the vertical aligment of the dropdown list? As you can see, it is overlapping with the Spinner in the first image (the line under it isn't visible as it is in the second image).
The attribute you want is android:popupBackground on the Spinner element.
If you look closely, the holo popup also overlaps the spinner some, but there is a bunch of padding for the drop shadow, so it looks good.
However, you can use android:dropDownVerticalOffset on the Spinner element to adjust it.
We came across the same issue. It has to do with the Android Holo theme generator.
Here are the lines that you should remove from your Theme.xml file...
<item name="android:spinnerStyle">#style/SpinnerCustom</item>
<item name="android:spinnerDropDownItemStyle">#style/SpinnerDropDownItemCustom</item>
<item name="android:popupMenuStyle">#style/PopupMenu.Custom</item>
<item name="android:dropDownListViewStyle">#style/DropDownListView.Custom</item>
<item name="android:actionDropDownStyle">#style/DropDownNav.Custom</item>
...by removing these, we now have the standard Holo.Light theme on the spinner dropdowns.
You need to change the parent of spinnertheme to android:Widget.Holo.Light.Spinner
<style name="SpinnerTHEME" parent="android:Widget.Holo.Light.Spinner">
<style name="spinner_style" parent="android:Widget.Holo.Light.Spinner">
<item name="android:paddingLeft">#dimen/ten_dp</item>
<item name="android:paddingRight">#dimen/ten_dp</item>
</style>

How to change SearchView default icon?

I've used "Android Action Bar Style Generator" in order to generate my own Holo theme.
Then I've added two icons to the action bar, one for a searchFilter and one for a file picker, both icons are white. File picker icon (at the right) looks good, but somehow search icon looks dark grey. When typing on the search text view, close button also looks dark grey.
I've tried changing color of the actionbar and also from the searchview, without success. Why is the search view showing this color? How can I change it?
Thank you very much.
UPDATE: I thought that my app was using my icon but it doesn't, it uses the default search view icon, so my question actually is, how do I change the default icon of the search view?
This sentence at the menu.xml file is not working:
android:icon="#drawable/selectable_header_search"
Unfortunately, there is no easy way to change the SearchView icon to a custom drawable, since the theme attribute searchViewSearchIcon is not public. See this answer for details.
However, I think that your problem is caused by inheriting from the wrong theme. Please use android:Theme.Holo.Light.DarkActionBar as the base for your theme. Then the default icons on the action bar should have a light color.
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
...
</style>
Since the searchViewSearchIcon attribute is not public, you can change the icon using the following code:
int searchIconId = searchView.getContext().getResources().getIdentifier("android:id/search_button",null, null);
ImageView searchIcon = (ImageView) searchView.findViewById(searchIconId);
searchIcon.setImageResource(R.drawable........);
Try to set up in the showAsAction this option: *MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW*
Without this option the SearchView do not take the icon which you setup for action button.
menu.add("Search")
.setIcon(
getResources().getDrawable(
R.drawable.selectable_header_search))
.setActionView(searchView)
.setShowAsAction(
MenuItem.SHOW_AS_ACTION_ALWAYS
| MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW
| MenuItem.SHOW_AS_ACTION_WITH_TEXT);
The easiest way I've found to change the default searchview icon in the action bar is in your onPrepareOptionsMenu. You can see my answer here to a similar question!
In your theme style include this:
<style name="YourTheme.Toolbar">
<item name="searchViewStyle">#style/YourActionBarSearch</item>
<item name="editTextColor">#color/your_ab_text_color</item>
<item name="android:textColorHint">#color/your_ab_hint_color</item>
</style>
You can now define the style of the SearchView with searchViewStyle, and editTextColor will set the color of the text in the search box. By setting android:textColorHint you will also set the color of the hint, e.g. "Search...".
<style name="YourActionBarSearch" parent="#style/Widget.Holo.SearchView">
<item name="searchIcon">#drawable/ic_ab_search</item>
<item name="queryBackground">#null</item>
<item name="submitBackground">#null</item>
<item name="searchHintIcon">#drawable/ic_ab_small_search</item>
<item name="defaultQueryHint">#string/toolbar_search_hint</item>
<item name="closeIcon">#drawable/ic_ab_small_search_close</item>
</style>
This will style your search view as you like, more or less. The field searchIcon is the icon in the action bar. The field searchHintIcon is the small icon to the left of the hint in the search field. The field closeIcon is the close icon at the right side of the search field.
Check this out, for more style settings:
$ANDROID_SDK/platforms/android-24/data/res/values/styles_holo.xml
For those like me hoping to find a way to truly change the icon, you can use this with actionbar sherlock:
// Getting the 'search_icon'
ImageView searchIcon = (ImageView)searchView.findViewById(R.id.abs__search_button);
// Setting background of 'search_plate' to earlier defined drawable.
searchIcon.setImageResource(R.drawable.search_button_selector);
You can't change the default one with the common way android:icon, because the field related to it had been set to private.

Categories

Resources