- 論壇徽章:
- 0
|
本帖最后由 小麥麥子007 于 2015-06-11 17:10 編輯
在Android開(kāi)發(fā)中,我們都會(huì)遇到對(duì)話框的編寫需求,但往往也就是這個(gè)時(shí)候最容易出現(xiàn)問(wèn)題。很多新手Android開(kāi)發(fā)人員對(duì)dialog樣式編寫都存在各種各樣的疑問(wèn),下邊小編就統(tǒng)一為大家分享下Android中自定義dialog樣式的方法。
1、自定義Dialog
final Dialog dialog = new Dialog(this, R.style.Theme_dialog);
2、窗口布局
View contentView = LayoutInflater.from(this).inflate(R.layout.select_list_dialog, null);
3、把設(shè)定好的窗口布局放到dialog中
dialog.setContentView(contentView);
4、設(shè)定點(diǎn)擊窗口空白處取消會(huì)話
dialog.setCanceledOnTouchOutside(true);
5、具體的操作
ListView msgView = (ListView) contentView.findViewById(R.id.listview_flow_list);
6、展示窗口
dialog.show();
例:
final Dialog dialog = new Dialog(this, R.style.Theme_dialog);
View contentView = LayoutInflater.from(this).inflate(R.layout.select_list_dialog, null);
dialog.setContentView(contentView);
dialog.setCanceledOnTouchOutside(true);
ListView msgView = (ListView) contentView.findViewById(R.id.listview_flow_list);
TextView titleText = (TextView) contentView.findViewById(R.id.title);
titleText.setText("請(qǐng)選擇銀行卡");
SelectBankCardDialogAdapter adapter = new SelectBankCardDialogAdapter(this, mBankcardList);
msgView.setAdapter(adapter);
msgView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView parent, View view, int position, long id) {
// Toast.makeText(RechargeFlowToMobileActivity.this,
// position+"", 0).show();
mSelectCard = mBankcardList.get(position);
String area = mSelectCard.getBank_card();
mCardNumberText.setText(area);
dialog.dismiss();
}
});
Button closeBtn = (Button) contentView.findViewById(R.id.close);
closeBtn.setClickable(true);
closeBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.show();
以上就是在Android開(kāi)發(fā)自定義dialog樣式的方法和步驟,可能對(duì)你來(lái)說(shuō)不是最好的方法,但是對(duì)于Android新手編寫對(duì)話框足夠了,如果你有更好的實(shí)現(xiàn)方法,也歡迎貼出來(lái)。
推薦學(xué)習(xí):麥子學(xué)院-Android開(kāi)發(fā)進(jìn)階
|
|