android button 點擊時改變顏色(2)


1.通過shape進行轉換

效果圖 平時:   單擊時 

2.設置一個button

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/button_selectors"/>

3.在drawable下新建shape_normal.xml和shape_pressed.xml兩個文件

4.分別打開兩個xml文件編寫代碼

 

5.在button_selector.xml中指定資源文件,運行即可!

 

 

 

 




免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM