2019年1月18日 星期五

Android ch4 5 單選訊息元件介紹



[Android]_ch4.5_單選訊息元件介紹

case 3:

String items[]={"紅色","綠色","藍色","紫色"};

DialogInterface.OnClickListener listener=new DialogInterface.OnClickListener() {

@Override

public void onClick(DialogInterface dialog, int which) {

switch(which){

case 0:

layout.setBackgroundColor(Color.RED);

break;

case 1:

layout.setBackgroundColor(Color.GREEN);

break;

case 2:

layout.setBackgroundColor(Color.BLUE);

break;

case 3:

layout.setBackgroundColor(new Color().rgb(255, 0, 255));

break;

}

}

};

return new AlertDialog.Builder(MainActivity.this)

.setIcon(R.drawable.ic_launcher)

.setTitle("設定背景顏色")

.setItems(items, listener)

.setPositiveButton("確定", new DialogInterface.OnClickListener() {

@Override

public void onClick(DialogInterface dialog, int which) {

finish();

}

})

.setNegativeButton("取消", new DialogInterface.OnClickListener() {



@Override

public void onClick(DialogInterface dialog, int which) {

dialog.cancel();

}

})

.setCancelable(false)

.show();

沒有留言:

張貼留言

Ether.fi Cash Card 一張所有人必備的加密貨幣信用卡   [Ether.fi Cash Card] : https://www.ether.fi/app/cash/sign-up?ref_code=d27f8523 ------國際交易所------ [Bitg...