Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change the Color of Highlighted text in Android

Tags:

android

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.

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.

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?

like image 274
sgargan Avatar asked Aug 10 '10 16:08

sgargan


People also ask

How do I change the highlight color on my Android?

Android system accent colors can be changed by going to Settings > Wallpaper & style > Basic colors and picking your favorite color.

How do you change the highlight color on text?

Highlight selected text Select the text that you want to highlight. Go to Home and select the arrow next to Text Highlight Color. Select the color that you want. Note: Use a light highlight color if you plan to print the document by using a monochrome palette or printer.


2 Answers

Try:<item name="android:textColorHighlight">your_color</item>

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>
like image 159
Shubham Arora Avatar answered Sep 20 '22 15:09

Shubham Arora


Did you try @android:attr/textColorPrimaryInverse ?

like image 32
fedj Avatar answered Sep 16 '22 15:09

fedj