Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
313 views
in Technique[技术] by (71.8m points)

android - What is the "state_focused" state for a Button?

I would like a Button background to remain a certain color after the button is clicked, and change colors again when some other button is pressed. I thought this was the "state_focused" state.

But the only two states I seem to have for my Button is pressed or not pressed.

Do I understand the state_focused state correctly, or is my StateListDrawable (see below) wrong?

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_focused="true" android:state_pressed="false"><shape>
            <solid android:color="#00ff00" />
        </shape></item>
    <item android:state_pressed="true"><shape>
            <solid android:color="#ff0000" />
        </shape></item>
    <item><shape>
            <solid android:color="#0000ff" />
        </shape></item>

</selector>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

state_focused is whenever the button is focused on using a dpad or the trackball. Views don't generally show a focused state when using touch.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...