Android自定义对话框
2014-12-11 16:53
183 查看
在代码中需要这项写就可以了:
//布局文件转换为view对象
LayoutInflater inflaterDl = LayoutInflater.from(this);
RelativeLayout layout = (RelativeLayout)inflaterDl.inflate(R.layout.layout_dialog, null );
//对话框
final Dialog
dialog = newAlertDialog.Builder(SettingActivity.this).create();
dialog.show();
dialog.getWindow().setContentView(layout);
//取消按钮
Button btnCancel = (Button) layout.findViewById(R.id.dialog_cancel);
btnCancel.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View
v) {
Toast.makeText(getApplicationContext(), "cancel",
Toast.LENGTH_SHORT).show();
}
});
//确定按钮
Button btnOK = (Button) layout.findViewById(R.id.dialog_ok);
btnOK.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View
v) {
Toast.makeText(getApplicationContext(), "ok",
Toast.LENGTH_SHORT).show();
}
});
//关闭按钮
ImageButton btnClose = (ImageButton) layout.findViewById(R.id.dialog_close);
btnClose.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View
v) {
dialog.dismiss();
}
});
非常easy!自己动手吧。
//布局文件转换为view对象
LayoutInflater inflaterDl = LayoutInflater.from(this);
RelativeLayout layout = (RelativeLayout)inflaterDl.inflate(R.layout.layout_dialog, null );
//对话框
final Dialog
dialog = newAlertDialog.Builder(SettingActivity.this).create();
dialog.show();
dialog.getWindow().setContentView(layout);
//取消按钮
Button btnCancel = (Button) layout.findViewById(R.id.dialog_cancel);
btnCancel.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View
v) {
Toast.makeText(getApplicationContext(), "cancel",
Toast.LENGTH_SHORT).show();
}
});
//确定按钮
Button btnOK = (Button) layout.findViewById(R.id.dialog_ok);
btnOK.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View
v) {
Toast.makeText(getApplicationContext(), "ok",
Toast.LENGTH_SHORT).show();
}
});
//关闭按钮
ImageButton btnClose = (ImageButton) layout.findViewById(R.id.dialog_close);
btnClose.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View
v) {
dialog.dismiss();
}
});
非常easy!自己动手吧。
相关文章推荐
- Android---功能模块一之颜色选择器自定义Preference 对话框
- Android自定义对话框列表
- Android自定义对话框的大小
- Android对话框的自定义及透明效果
- android自定义大小对话框
- android 自定义对话框 背景透明
- Android自定义Dialog对话框
- Android自定义对话框
- android 自定义对话框 背景透明
- android自定义对话框
- 20. android dialog——自定义对话框之一
- Android简明开发教程十八:自定义对话框 Transform
- Android简明开发教程十八:自定义对话框 Transform
- Android 对话框进阶(自定义)
- android自定义对话框
- Android Dialog( 自定义对话框)
- Android简明开发教程十八:自定义对话框 Transform
- android 自定义对话框
- android Dialog 各种Dialog 三个选项的、进度条的、单选的、多选的、自定义的对话框
- android Dialog 各种Dialog 三个选项的、进度条的、单选的、多选的、自定义的对话框