国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
android 根據(jù)button不同狀態(tài)顯示不同(背景)圖片
網(wǎng)上的思路不錯,我只做了基于xml的實現(xiàn)。先來貼一段網(wǎng)上的經(jīng)典code:
<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="false" android:drawable="@drawable/button_add" />
<item android:state_pressed="true" android:drawable="@drawable/button_add_pressed" />
<item android:state_focused="true" android:drawable="@drawable/button_add_pressed" />
<item android:drawable="@drawable/button_add" />
</selector>

這個文件放在drawable目錄下面。命名為button_add_x.xml
使用的時候

<ImageButton
android:id="@+id/ImageButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#00000000"
android:src="@drawable/button_add_x"
>
</ImageButton>


按照這種方法 我試了多次,發(fā)現(xiàn)根本不能生效。后來才發(fā)現(xiàn),這方法是針對ImageButton的,于是查了一下Button和ImageButton的區(qū)別,如果區(qū)別不大,我就打算把我自己的Button換成ImageButton了,但結果令我失望了,區(qū)別還不小呢,主要是這2種控件對于實現(xiàn)onClick方法的機制不同,想想就復雜,如果貿然換了,編譯的時候恐怕要出現(xiàn)很多error。
再著,這方法并沒有改變button的background,而我們基于button去實現(xiàn)圖片一般都是直接+background的,對么?
下面貼我的code:
<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="false" android:drawable="@drawable/xxx1" />
<item android:state_pressed="true" android:drawable="@drawable/xxx2" />
<item android:state_focused="true" android:drawable="@drawable/xxx3" />
<-- 這里還可以加N多效果和動作 只要你用的到 -->
<item android:drawable="@drawable/xxx4" />
</selector>
這個文件沒有不同,起名為button_add_x.xml 放在drawable下。
使用的時候有所不同
<Button
android:id="@+id/Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/button_add_x" <---這里background直接指向剛剛編寫的文件
//這行不需要--->android:src="@drawable/button_add_x"
>
</Button>
ok,編譯 push后就生效了。如果你原來的background指向的是一張.png圖片的話,那么把它換成一個自己制作的文件就好。

本站僅提供存儲服務,所有內容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權內容,請點擊舉報。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
Android根據(jù)Button狀態(tài)(normal,focused,pressed)顯示不同...
Android利用selector設置按鈕不同狀態(tài)下的背景圖片
xml中,button改變背景顏色方法
向android 的狀態(tài)欄中加入快捷按鈕(home,back,menu等等)的方法(續(xù)) ...
Android之給ImageView添加點擊效果
定義xml為drawable文件并根據(jù)狀態(tài)改變顯示的圖片資源
更多類似文章 >>
生活服務
分享 收藏 導長圖 關注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服