日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

使用 XML 实现按钮改变焦点设置背景图

發布時間:2024/8/23 44 豆豆
生活随笔 收集整理的這篇文章主要介紹了 使用 XML 实现按钮改变焦点设置背景图 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

在 drawable 文件夾中添加一個 advancedbutton.xml 設置<selector>和 <item>標簽

<?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"
android:drawable="@drawable/onfocusimage"????????????? // onfocusimage是圖片 在drawable文件夾中放的圖片
/>
<item
android:state_focused="true"???????????????????????????? //獲取焦點并按下
android:state_pressed="true"
android:drawable="@drawable/clickimage"
/>
<item
android:state_focused="false"????????????????????????????????? //失去焦點時
android:state_pressed="true"
android:drawable="@drawable/clickimage"
/>
<item android:drawable="@drawable/defaultimage"/>??????????? //默認
</selector>

?

設置 ImageButton 的 android:background 屬性值

<ImageButton
android:id="@+id/image_Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/advancedbutton"???????? //設置背景圖
/>

轉載于:https://www.cnblogs.com/hao222/p/3488623.html

總結

以上是生活随笔為你收集整理的使用 XML 实现按钮改变焦点设置背景图的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。