android button setPressed after onClick

前端 未结 7 1397
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-03 15:27

yesterday I noticed the possibility to integrate Fragments in older API Levels through the Compatibility package, but thats not really essential for the question. :)

相关标签:
7条回答
  • 2020-12-03 16:07

    Use ToggleButton instead of Button.

    <ToggleButton
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="@drawable/topping_selector"
        android:checked="false"
        android:textOff="Topping2"
        android:textOn="Topping2" />
    

    topping_selector.xml:

    <selector xmlns:android="http://schemas.android.com/apk/res/android">
    
        <item android:state_checked="true" 
            android:drawable="@drawable/btn_topping_on" />
    
        <item android:state_checked="false" 
            android:drawable="@drawable/btn_topping_off" />
    
    </selector>
    
    0 讨论(0)
提交回复
热议问题