android中使用下拉列表、圖像按鈕時(shí)的常見(jiàn)問(wèn)題_第1頁(yè)
android中使用下拉列表、圖像按鈕時(shí)的常見(jiàn)問(wèn)題_第2頁(yè)
android中使用下拉列表、圖像按鈕時(shí)的常見(jiàn)問(wèn)題_第3頁(yè)
android中使用下拉列表、圖像按鈕時(shí)的常見(jiàn)問(wèn)題_第4頁(yè)
android中使用下拉列表、圖像按鈕時(shí)的常見(jiàn)問(wèn)題_第5頁(yè)
已閱讀5頁(yè),還剩6頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

北京信息職業(yè)技術(shù)學(xué)院|范美英Android中使用下拉列表、圖像按鈕時(shí)的常見(jiàn)問(wèn)題問(wèn)題描述1如何實(shí)現(xiàn)點(diǎn)擊圖像按鈕時(shí)顯示類(lèi)似左右圖所示的效果?Android中使用下拉列表、圖像按鈕時(shí)的常見(jiàn)問(wèn)題|問(wèn)題描述問(wèn)題解決方案1思路介紹:在Java中為圖片按鈕增加觸摸監(jiān)聽(tīng)的函數(shù)來(lái)實(shí)現(xiàn)圖片切換。具體地,當(dāng)圖片按下時(shí),修改按鈕的背景圖片,當(dāng)抬起時(shí)再修改為正常的圖片顯示,代碼如左。Android中使用下拉列表、圖像按鈕時(shí)的常見(jiàn)問(wèn)題|問(wèn)題解決方案ImageButton

btn

=

(ImageButton)findViewById(R.id.imageButton1);

btn.setOnTouchListener(new

View.OnTouchListener(){

public

boolean

onTouch(View

v,

MotionEvent

event)

{

if(event.getAction()

==

MotionEvent.ACTION_DOWN){

//重新設(shè)置按下時(shí)的背景圖片

((ImageButton)v).setImageDrawable(getResources().getDrawable(R.drawable.android_btn_pressed));

}else

if(event.getAction()

==

MotionEvent.ACTION_UP){

//再修改為抬起時(shí)的正常圖片

((ImageButton)v).setImageDrawable(getResources().getDrawable(R.drawable.android_btn));

}

return

false;

}

});

問(wèn)題解決方案2給按鈕配置XML文件來(lái)實(shí)現(xiàn)圖片按鈕的背景切換步驟1:在layout或drawable文件夾下添加一個(gè)image_btn_press.xml文件,代碼如左步驟2:在main.xml中設(shè)置圖片按鈕的屬性,將上面的xml文件添加到圖片按鈕的background屬性中,使用格式為:android:background="@layout/image_btn_press"Android中使用下拉列表、圖像按鈕時(shí)的常見(jiàn)問(wèn)題|問(wèn)題解決方案<?xml

version="1.0"

encoding="utf-8"?>

<selector

xmlns:android="/apk/res/android">

<item

android:state_pressed="false"

android:drawable="@drawable/android_btn"

/>

<item

android:state_focused="true"

android:drawable="@drawable/android_btn"

/>

<item

android:state_pressed="true"

android:drawable="@drawable/android_btn_pressed"

/>

</selector>

問(wèn)題描述2如左圖所示,如何實(shí)現(xiàn)下拉列表的聯(lián)動(dòng)?比如:當(dāng)?shù)?個(gè)下拉列表中選擇北京時(shí),第2個(gè)列表的數(shù)據(jù)自動(dòng)設(shè)置為北京的各區(qū)縣;當(dāng)?shù)?個(gè)下拉列表中選擇東城區(qū)時(shí),第3個(gè)列表的數(shù)據(jù)自動(dòng)設(shè)置為東城區(qū)的各個(gè)子區(qū);Android中使用下拉列表、圖像按鈕時(shí)的常見(jiàn)問(wèn)題|問(wèn)題描述問(wèn)題解決方案1//預(yù)設(shè)省級(jí)選項(xiàng)值privateString[]province=newString[]{"北京","上海","天津","廣東"};//,"重慶","黑龍江","江蘇","山東","浙江","香港","澳門(mén)"};//預(yù)設(shè)地級(jí)選項(xiàng)值

privateString[][]city=newString[][]{

{"東城區(qū)","西城區(qū)","崇文區(qū)","宣武區(qū)","朝陽(yáng)區(qū)","海淀區(qū)","豐臺(tái)區(qū)","石景山區(qū)","門(mén)頭溝區(qū)","房山區(qū)","通州區(qū)","順義區(qū)","大興區(qū)","昌平區(qū)","平谷區(qū)","懷柔區(qū)","密云縣","延慶縣"},{"長(zhǎng)寧區(qū)","靜安區(qū)","普陀區(qū)","閘北區(qū)","虹口區(qū)"},

{"和平區(qū)","河?xùn)|區(qū)","河西區(qū)","南開(kāi)區(qū)","河北區(qū)","紅橋區(qū)","塘沽區(qū)","漢沽區(qū)","大港區(qū)","東麗區(qū)"},{"廣州","深圳","韶關(guān)","珠海","汕頭","佛山","湛江","肇慶","江門(mén)","茂名","惠州","梅州","汕尾","河源","陽(yáng)江","清遠(yuǎn)","東莞","中山","潮州","揭陽(yáng)","云浮"}Android中使用下拉列表、圖像按鈕時(shí)的常見(jiàn)問(wèn)題|問(wèn)題解決方案問(wèn)題解決方案1 };//預(yù)設(shè)縣級(jí)選項(xiàng)值

privateString[][][]county=newString[][][]{{//北京

{"無(wú)"},{"無(wú)"},{"無(wú)"},{"無(wú)"},{"無(wú)"},{"無(wú)"},{"無(wú)"},{"無(wú)"},{"無(wú)"},{"無(wú)"},{"無(wú)"},{"無(wú)"},{"無(wú)"},{"無(wú)"},{"無(wú)"},{"無(wú)"},{"無(wú)"},{"無(wú)"}},{//上海

{"無(wú)"},{"無(wú)"},{"無(wú)"},{"無(wú)"},{"無(wú)"}},{//天津

{"無(wú)"},{"無(wú)"},{"無(wú)"},{"無(wú)"},{"無(wú)"},{"無(wú)"},{"無(wú)"},{"無(wú)"},{"無(wú)"},{"無(wú)"}},Android中使用下拉列表、圖像按鈕時(shí)的常見(jiàn)問(wèn)題|問(wèn)題解決方案問(wèn)題解決方案1{//廣東{"海珠區(qū)","荔灣區(qū)","越秀區(qū)","白云區(qū)","蘿崗區(qū)","天河區(qū)","黃埔區(qū)","花都區(qū)","從化市","增城市","番禺區(qū)",沙區(qū)"},//廣州

{"寶安區(qū)","福田區(qū)","龍崗區(qū)","羅湖區(qū)","南山區(qū)","鹽田區(qū)"},//深圳{"武江區(qū)","湞江區(qū)","曲江區(qū)","樂(lè)昌市","南雄市","始興縣","仁化縣","翁源縣","新豐縣","乳源縣"}//韶關(guān)}};Android中使用下拉列表、圖像按鈕時(shí)的常見(jiàn)問(wèn)題|問(wèn)題解決方案問(wèn)題解決方案1Android中使用下拉列表、圖像按鈕時(shí)的常見(jiàn)問(wèn)題|問(wèn)題解決方案逐級(jí)設(shè)置問(wèn)題解決方案1Android中使用下拉列表、圖像按鈕時(shí)的常見(jiàn)問(wèn)題|問(wèn)題解決方案逐級(jí)

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論