简体   繁体   中英

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 (eg white).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM