Change the selection color to Button and TextView on Android

I am developing an application, and when I run it in the emulator, and I selected the button (did not click!), It shows an orange layer above it. When I click on it, I turn yellow. On HTC, the orange / yellow overlay is green. On the Samsung Galaxy S it is blue.

I want my app to have the same highlight color throughout the app (blue to be precise).

Is it possible? If so, how?

+3
source share
4 answers
+2
source

, . Themes, .

+1

You're right

But u also sets the background color at runtime

& Other

Is it possible that HTC / Samsung has a different version of Android?

make it happen

0
source

Create a selector in your folder with a choice of e.g. drawable / item_selctor.xml

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

In your code or xml file use

 item.setBackgroundResource(R.drawable.item_selector);

in code or

android:background="@drawable/item_selector"

in xml layout file

0
source

Source: https://habr.com/ru/post/1784713/


All Articles