Android基于ImageView繪制的開關(guān)按鈕效果示例
本文實(shí)例講述了Android基于ImageView繪制的開關(guān)按鈕效果。分享給大家供大家參考,具體如下:
今天弄了一下用圖片繪制開關(guān)按鈕.
效果圖:


還有我兩張start圖片和stop圖片就是上面的圖片,到時(shí)候大家可以按照自己的圖片調(diào)用..
Main.xml文件
在xml進(jìn)入這段代碼就ok了。
<ImageView Android:id="@+id/start" android:layout_width="150.px" android:layout_height="80.px" android:src="@drawable/start" android:layout_x="120.0px" android:layout_y="250.0px" />
Activity文件
public class two extends Activity implements OnClickListener{
private ImageView start =null; // 開始
protected boolean isBrewing = false; // 按鈕置換
public void onCreate(Bundle savedInstanceState) {
//設(shè)置全屏
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.two);
// 綁定
start = (ImageView) findViewById(R.id.start);
start.setOnClickListener(this);
}
//開始
public void startView(){
Bitmap bmp=BitmapFactory.decodeResource(getResources(), R.drawable.stop);//打開資源圖片
start.setImageBitmap(bmp);
isBrewing = true;
}
//停止
public void stopView(){
Bitmap bmp=BitmapFactory.decodeResource(getResources(), R.drawable.start);//打開資源圖片
start.setImageBitmap(bmp);
isBrewing = false;
}
@Override
public void onClick(View v) {
if(v==start){
if(isBrewing)
stopView();
else
startView();
}
}
}
ok完成..
更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android布局layout技巧總結(jié)》、《Android視圖View技巧總結(jié)》、《Android開發(fā)入門與進(jìn)階教程》、《Android調(diào)試技巧與常見問題解決方法匯總》、《Android多媒體操作技巧匯總(音頻,視頻,錄音等)》、《Android基本組件用法總結(jié)》及《Android控件用法總結(jié)》
希望本文所述對大家Android程序設(shè)計(jì)有所幫助。
- Android開發(fā)之開關(guān)按鈕用法示例
- Android開發(fā)之開關(guān)按鈕控件ToggleButton簡單用法示例
- Android 自定義Switch開關(guān)按鈕的樣式實(shí)例詳解
- Android中ToggleButton開關(guān)狀態(tài)按鈕控件使用方法詳解
- Android動畫 實(shí)現(xiàn)開關(guān)按鈕動畫(屬性動畫之平移動畫)實(shí)例代碼
- Android自定義View實(shí)現(xiàn)開關(guān)按鈕
- Android 仿蘋果IOS6開關(guān)按鈕
- Android模擬開關(guān)按鈕點(diǎn)擊打開動畫(屬性動畫之平移動畫)
- Android自定義實(shí)現(xiàn)開關(guān)按鈕代碼
- Android自定義開關(guān)按鈕源碼解析
相關(guān)文章
Android實(shí)現(xiàn)自動提取短信驗(yàn)證碼功能
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)自動提取短信驗(yàn)證碼功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-01-01
Android 對Map按key和value分別排序的實(shí)例
下面小編就為大家?guī)硪黄狝ndroid 對Map按key和value分別排序的實(shí)例。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-12-12
android編程實(shí)現(xiàn)sd卡讀取數(shù)據(jù)庫的方法
這篇文章主要介紹了android編程實(shí)現(xiàn)sd卡讀取數(shù)據(jù)庫的方法,涉及Android權(quán)限控制及針對sd卡與數(shù)據(jù)庫的相關(guān)操作技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-11-11
Android基于BaseExpandableListAdapter實(shí)現(xiàn)的二級列表仿通話記錄功能詳解
這篇文章主要介紹了Android基于BaseExpandableListAdapter實(shí)現(xiàn)的二級列表仿通話記錄功能,結(jié)合具體實(shí)例形式分析了Android實(shí)現(xiàn)通話記錄功能的布局與功能相關(guān)操作技巧,需要的朋友可以參考下2017-07-07
android ListActivity顯示圖標(biāo)實(shí)例
在ListActivity中顯示圖標(biāo),好像并不復(fù)雜,實(shí)現(xiàn)起來卻不輕松,我們下面一步步來實(shí)現(xiàn)ListActivity中顯示圖標(biāo)2013-11-11

