如何自定义Android Dialog的样式?
2个回答
展开全部
Android 中自定义Dialog的样式,主要是通过自定义的xml,然后加载到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、把设定好的窗口布局放到dialog中
dialog.setContentView(contentView);
4、设定点击窗口空白处取消会话
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("请选择银行卡");
SelectBankCardDialogAdapter adapter =new SelectBankCardDialogAdapter(this, mBankcardList);
msgView.setAdapter(adapter);
msgView.setOnItemClickListener(newOnItemClickListener() {
@Override
public void onItemClick(AdapterViewparent, 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(newView.OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.show();
以上就是在Android开发自定义dialog样式的方法和步骤,android很多的控件都提供了接口或者方法进行样式的定义和修改。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询