最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android編程動(dòng)態(tài)按鈕實(shí)現(xiàn)方法

 更新時(shí)間:2016年10月27日 09:58:48   作者:Wallace  
這篇文章主要介紹了Android編程動(dòng)態(tài)按鈕實(shí)現(xiàn)方法,分享了onTouch方法及xml調(diào)用兩種實(shí)現(xiàn)技巧,需要的朋友可以參考下

本文實(shí)例講述了Android編程動(dòng)態(tài)按鈕實(shí)現(xiàn)方法。分享給大家供大家參考,具體如下:

第一種: 該方法通過(guò)onTouch來(lái)實(shí)現(xiàn),

btn3 = (ImageButton) findViewById(R.id.ImageButton03);
btn3.setOnTouchListener(touchListener3);
View.OnTouchListener touchListener = new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
ImageButton imageBtn = (ImageButton) v;
if(event.getAction() == MotionEvent.ACTION_DOWN){
//更改為按下時(shí)的背景圖片
imageBtn .setImageResource(R.drawable.pressed);
}else if(event.getAction() == MotionEvent.ACTION_UP){
//改為抬起時(shí)的圖片
imageBtn .setImageResource(R.drawable.released);
}
return false;
}
};

第二種: 通過(guò)XML來(lái)實(shí)現(xiàn)

用XML文件實(shí)現(xiàn):

<?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>

這個(gè)文件放在drawable目錄下面。命名為button_add_x.xml

使用的時(shí)候:

<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>

更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專(zhuān)題:《Android布局layout技巧總結(jié)》、《Android視圖View技巧總結(jié)》、《Android開(kāi)發(fā)入門(mén)與進(jìn)階教程》、《Android調(diào)試技巧與常見(jiàn)問(wèn)題解決方法匯總》、《Android多媒體操作技巧匯總(音頻,視頻,錄音等)》、《Android基本組件用法總結(jié)》及《Android控件用法總結(jié)

希望本文所述對(duì)大家Android程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論

台湾省| 湄潭县| 文安县| 汝阳县| 台东市| 赤峰市| 揭西县| 宣化县| 临江市| 红安县| 木兰县| 宁都县| 巴中市| 毕节市| 怀远县| 辉南县| 祁门县| 金山区| 普洱| 修水县| 江永县| 清流县| 花莲县| 建宁县| 盐津县| 理塘县| 宁陵县| 榆社县| 石狮市| 高邮市| 玉山县| 静乐县| 清丰县| 永新县| 六枝特区| 连云港市| 靖宇县| 日照市| 河北区| 留坝县| 沿河|