在Android中更改突出显示的文本的颜色 [英] Change the Color of Highlighted text in Android

查看:53
本文介绍了在Android中更改突出显示的文本的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不确定这是否可行,也许有人可以让我挺直.我在android应用程序中有一个EditText视图,该应用程序在蓝色背景上有白色文本.选择文本后(通过长按和编辑对话框),我希望高亮显示为白色,并将文本颜色更改为黑色.令人讨厌的是,虽然似乎没有一种方法可以在高亮显示上设置文本的颜色.您可以使用 textColorHighlight 设置突出显示颜色,但不能使用文本颜色设置,因此设置带有白色文本的白色突出显示会导致白色块很大.

I'm not sure that this is possible, perhaps someone can set me straight. I have an EditText View in an android application that has white text on a blue background. When the text is selected (via a long press and the edit dialog), I'd like have the highlight be white and change the text color to be black. Annoyingly though there does not seem to be a way to set the color of the text on highlight. You can set the highlight color using textColorHighlight, but not the text color, so setting a white highlight with white text results in a big white block.

您似乎可以在xml中声明性地处理一些琐碎的事情,但是尽管我尝试了多种样式和颜色的组合,但是我仍然无法更改颜色.

It seems like it should be something trivial you can do declaratively in the xml, but though I've tried many combinations of styles and colors, I've not been able to change the color.

检查其他标准应用程序,似乎文本颜色似乎从未改变,因此我认为这是一件不容易做到的事情.我宁愿不必尽可能简单地将EditText子类化.我想念什么吗?可以在xml视图中完成吗?

Checking other standard applications it seems that the text color never seems to change so I'm thinking this is something that's not easily done. I'd rather not have to subclass the EditText if at all possible just to something so simple. Am I missing something? Can this be done in the view xml?

推荐答案

尝试:<项目名称="android:textColorHighlight">您的颜色</项目>

以您作为主题的样式.例如

in the style that you as your theme. For e.g.

<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="colorPrimary">your_color1</item>
    <item name="colorPrimaryDark">your_color2</item>
    <item name="colorAccent">your_color3</item>
    <item name="android:textColor">your_color4/item>
    <item name="android:textColorHighlight">your_color</item>
</style>

然后使用此样式作为清单文件中活动的主题.例如-

then use this style as the theme for your activity in the manifest file. For e.g.-

<activity
    android:name=".youractivity"
    android:label=""
    android:theme="@style/AppTheme.NoActionBar"       
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>

这篇关于在Android中更改突出显示的文本的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆