且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

按下 android 按钮状态

更新时间:2023-11-18 13:13:46

Button 是您在 Activity 中唯一显示的东西吗?如果是这样,那么当窗口加载时它将被聚焦(触发 selector 中的第三项),并且您将无法离开它.如果您只想在按下时更改,请删除第三行.当你在它的时候,删除第一行,因为当窗口没有聚焦时,按钮永远不会被按下.

Is the Button the only thing you have displayed in your Activity? If so, then it will be focused (triggering the third item in your selector) when the window loads, and you won't be able to navigate away from it. If you want to change only when pressed, delete that third line. While you're at it, delete the first line, as the button will never be pressed when the window isn't focused.

其实我建议这样的代码:

In fact, I suggest this code:

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