简体   繁体   中英

How to change the overall Focus color for all the components?

I want to change the focus color which is blue by default to some custom color? What is the simple way to do this? Thanks in advance.

you want to make a StateListDrawable and set it as the background colour View.setBackgroundResource(R.id.drawable_name): in XML it is:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false" android:drawable="@color/button_disabled"/>
<item android:state_pressed="true" android:drawable="@color/button_pressed"/>
<item android:state_selected="true" android:drawable="@color/button_selected"/>
<item android:state_focussed="true" android:drawable="@color/button_focussed"/>
<item android:drawable="@color/button_transparent"/>

the drawables can be defined colours in res/values/colors.xml eg

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <!--  buttons -->
    <color name="button_enabled">#88000000</color>
    <color name="button_disabled">#88666666</color>
    <color name="button_pressed">#88ff8800</color>
    <color name="button_selected">#cc0088bb</color>
    <color name="button_focussed">#cc8800bb</color>
    <color name="button_transparent">#00000000</color>
</resources> 

the drawable can be used the same way you would use any other drawable resource

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