julian9876
julian9876

Reputation: 61

How to change/disable onClick highlight color

When i click on an item, it highlights orange.

Ive tried:

android:state_pressed="false"

If there any way to stop it from doing this, or change the colour of the highlight?

Upvotes: 2

Views: 6336

Answers (4)

Chris Klingler
Chris Klingler

Reputation: 5296

Like everyone is saying if you set the background of a button it will not highlight when clicked, setting it to null or to a clear color like so work well:

in your xml for the button:

android:background="@color/clear"

in your colors.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="clear">#00000000</color>
</resources>

Upvotes: 3

Sergios
Sergios

Reputation: 133

By changing the background of your item to android:background="@null" you will achieve the desired result. It worked for me for buttons.

Upvotes: 0

Shubhayu
Shubhayu

Reputation: 13552

Try this

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_selected="true" android:drawable="your_selected_drawable_or_color" />
    <item android:state_pressed="true" android:drawable="your_pressed_drawable_or_color" />
    <item android:drawable="your_default_drawable_or_color" />
</selector>

Play around with the combinations to get what suits u best.

Upvotes: 0

FUBUs
FUBUs

Reputation: 617

You need to change the background of your view by your own selector :

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"
    android:constantSize=["true" | "false"]
    android:dither=["true" | "false"]
    android:variablePadding=["true" | "false"] >
    <item
        android:drawable="@[package:]drawable/drawable_resource"
        android:state_pressed=["true" | "false"]
        android:state_focused=["true" | "false"]
        android:state_hovered=["true" | "false"]
        android:state_selected=["true" | "false"]
        android:state_checkable=["true" | "false"]
        android:state_checked=["true" | "false"]
        android:state_enabled=["true" | "false"]
        android:state_activated=["true" | "false"]
        android:state_window_focused=["true" | "false"] />
</selector>

Upvotes: 0

Related Questions