I'm using default PopupMenu. I've customized it in my XML style, and now it has a dark style. but I have a problem now: please look at this screenShot I've prepared:
As you can see the arrow is kind of hard to see and I really wish to avoid using popup window now. Is there any way that I could change it to a white arrow?
It's been a long time, but in case anyone else runs into this problem, you can leverage a style to fix this.
it looks like the color of the arrow is controlled by android:textColorSecondary, so if you are programmatically generating a popup menu, you could do something like this (in Kotlin):
val contextThemeWrapper = ContextThemeWrapper(context, R.style.PopupMenuStyle)
val popupMenu = PopupMenu(contextThemeWrapper, view)
val menu = popupMenu.menu
menu.addSubMenu(groupId, itemId, order, groupTitle)
menu.add(groupId, itemId, order, title1)
menu.add(groupId, itemId, order, title2)
etc...
and define your PopupMenuStyle like this in your styles.xml:
<style name="PopupMenuStyle" parent="#style/<some.parent.style>">
<!--this makes an the arrow for a menu's submenu white-->
<item name="android:textColorSecondary">#android:color/white</item>
</style>
custom theme and set listMenuViewStyle
<style name="AppTheme" parent="Theme.MaterialComponents.Light">
<item name="listMenuViewStyle">#style/listMenuViewStyle</item>
</style>
set subMenuArrow
<style name="listMenuViewStyle" parent="Base.Widget.AppCompat.ListMenuView">
<item name="subMenuArrow">#drawable/icon_sub_menu</item>
</style>
apply custom theme to activity
<activity android:name=".material.MyTopAppBarActivity"
android:theme="#style/AppTheme"/>
Related
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).
To change the default option menu icon color(3 vertical dote), i have tried adding
<item name="android:textColorSecondary">#color/white</item>
But it doesn't make any change. I think it is not working coz my AppTheme parent is Theme.AppCompat.Light.NoActionBar. So can anybody help me on this?
The easiest way of doing it is by adding
<item name="popupTheme">#style/ThemeOverlay.AppCompat.Light</item>
or
<item name="popupTheme">#style/ThemeOverlay.AppCompat.Dark</item>
to your primary Theme in order to change it to light or dark.
EDIT: In order to add any color for the overflow icon you would have to override the actionOverflowButtonStyle like so:
<style name="Theme.MyAppTheme" parent="Theme.AppCompat.NoActionBar">
<item name="actionOverflowButtonStyle">#style/OverFlow</item>
</style>
<style name="OverFlow" parent="#style/Widget.AppCompat.Light.ActionButton.Overflow">
<item name="android:src">#drawable/ic_overflow_icon</item>
</style>
You can easily create your own overflow icon from websites like Android Asset Studio
2019 - Easiest way to do is write the below code to your xml in toolbar code or where you want.
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
please give up vote if its work.
You can Either use your own drawable or get the default overFlowIcon and change its tint value like below:
bd.toolbar.overflowIcon?.setTint(Color.WHITE)
To change the drawable all together, you just have to create your own vector and set it like below:
bd.toolbar.overflowIcon = ContextCompat.getDrawable(this,R.drawable.ic_baseline_menu_24)
If you are using Toolbar, just add the following code in your Activity:
toolbar.setOverflowIcon(getDrawable(R.drawable.ic_more_vert_black_24dp));
By using this code, you can directly replace the "three dots" icon with any other icon of your choice. It worked for me.
I want to set the background of my popup menu like in the given image:
Is there any way to set this background for the given popup menu in android? If anyone have any idea please help me in accomplishing this.
you can style your pop-up menu in the xml file
Like this:
I simply change the color to #ffffff means Hex white!
<style name="style" parent="android:Theme.Holo.Light">
<item name="android:popupMenuStyle">...</item>
<item name="android:popupAnimationStyle">...</item>
<item name="android:popupBackground">#ffff</item>
<!-- etc etc -->
First, a few words about the app : minimum level is 16, I use a DrawerLayout (with the indicator) and have changed the background of my ActionBar.
When clicking on the home button to open the drawer, there is a blue pressed effect on both the image and the drawer indicator, that I'd like to remove. I tried setting selectableItemBackground in the styles to transparent, nearly everywhere I could think of, but that doesn't seem to change anything. Do anyone have a solution ?
Here is the image of this effect I'd like to remove :
Here is the styles.xml part for the ActionBar I'm using :
<style name="ActionBar.Solid.Bnp" parent="#android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">#drawable/action_bar_green</item>
<item name="android:titleTextStyle">#style/ActionBar.Title</item>
<item name="android:actionBarItemBackground">#null</item>
</style>
and finally the drawable used for background.
selectableItemBackground is close, but you need to use the actionBarItemBackground attribute instead.
For instance:
<style name="Your.Theme" parent="#android:style/Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarItemBackground">#null</item>
</style>
You should keep in mind that the system uses this attribute in the ActivityChooserView too, which is what the ShareActionProvider returns in ActionProvider.onCreateActionView.
To highlight all this, here are the results when you use #android:color/holo_red_light instead:
I want to use different ActionBar Icons depending on which style I use (Dark or Light).
I couldn't figure it out how, heres what I tried:
<style name="AppThemeDark" parent="Theme.Sherlock.ForceOverflow">
<item name="android:actionButtonStyle">#style/customActionButtonStyleDark</item>
<item name="actionButtonStyle">#style/customActionButtonStyleDark</item>
</style>
<style name="AppThemeLight" parent="Theme.Sherlock.Light.ForceOverflow">
<item name="android:actionButtonStyle">#style/customActionButtonStyleLight</item>
<item name="actionButtonStyle">#style/customActionButtonStyleLight</item>
</style>
<style name="customActionButtonStyleDark" >
<item name="#drawable/action_search">#drawable/action_search</item>
</style>
<style name="customActionButtonStyleLight" >
<item name="#drawable/action_search">#drawable/action_search_light</item>
</style>
I also tried to insert <item name="#drawable/action_search">#drawable/action_search</item> directly into the theme style, but nothing worked.
Any ideas how?
Even though you found a workaround, maybe this will help someone else. I found a simple way to do this in xml (what logcat's answer is referring to). The trick I used was to create custom attributes for my menu/actionbar icons. You have to have one attribute per menu item icon.
You need to create attrs.xml in your values folder, and add your custom attributes. Think of each attribute as a constant that your themes/styles set, and then your styles/views can use those contants to set properties.
<declare-styleable name="customAttrs">
<attr name="customSearchIcon" format="reference" />
</declare-styleable>
In your styles.xml in your values folder, have your themes/styles that set your custom icon attributes to drawable references.
<style name="AppThemeDark" parent="Theme.Sherlock.ForceOverflow">
<item name="customSearchIcon">#drawable/action_search</item>
</style>
<style name="AppThemeLight" parent="Theme.Sherlock.Light.ForceOverflow">
<item name="customSearchIcon">#drawable/action_search_light</item>
</style>
Lastly, in your [menu_name].xml in your menu folder, have your menu item set its icon to your matching custom icon attribute.
<item
android:id="#+id/menuitem_search"
android:icon="?attr/customSearchIcon"/>
Now, depending on what theme is set, the icon for the menu item will change. Also, this allows you to still have API specific versions of your drawables (light and dark) using resource identifiers with your drawable folders, so you can have different menu style icons for pre 3.0 and actionbar style icons for 3.0+.
Also, remember when setting a theme at runtime (vs AndroidManifest.xml), you must set it before calling setContentView() in your Activity. It is recommended to restart your activity after changing the theme of an Activity that has already been created.
I think you did not get theming :) When you are trying to do:
<style name="customActionButtonStyleDark" >
<item name="#drawable/action_search">#drawable/action_search</item>
</style>
You are trying to overload some attribute in theme with name "#drawable/action_search"
I have bad news for you, I think there is no such. So you can go to the theme Theme.Sherlock.ForceOverflow and it's parents and see what you can overload.
If nothing help's you, and you want to have custom attribute in your theme for different icons, It's different topic. You need to create attribute in attrs.xml, point your icon source to this new attribute and define attribute value in theme. For every different button.
Solved it, but gave it up to try it with XML, I did it now programmatically:
#Override
public boolean onCreateOptionsMenu(Menu menu) {
SharedPreferences prefs = getSharedPreferences("app", 0);
boolean isDark = "Dark".equals(prefs.getString("theme", "Dark"));
com.actionbarsherlock.view.MenuInflater inflater = getSupportMenuInflater();
inflater.inflate(R.menu.main, menu);
// set Icons
menu.findItem(R.id.menuitem_search).setIcon(isDark ? R.drawable.action_search : R.drawable.action_search_light);
menu.findItem(R.id.menuitem_add).setIcon(isDark ? R.drawable.content_new : R.drawable.content_new_light);
menu.findItem(R.id.menuitem_share).setIcon(isDark ? R.drawable.social_share : R.drawable.social_share_light);
return true;
}
See res/xml/ic_search.xml in blog post AppCompat — Age of the vectors (Chris Barnes)
Notice the reference to ?attr/colorControlNormal
<vector xmlns:android="..."
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0"
android:tint="?attr/colorControlNormal">
<path
android:pathData="..."
android:fillColor="#android:color/white"/>
</vector>