如何设置Dialog铺满全屏,更改Dialog的显示位置
1个回答
展开全部
AndroidDialog示例代码:
1.创建象框
AlertDialog.Builder builder = new Builder(context);
builder.setTitle("请输入"); //设置框标题
builder.setIcon(android.R.drawable.btn_star); //设置框标题前图标
2.创建EditText输入框
final EditText edit = new EditText(context);
3.输入框赋值给Dialog,并增加确定取消按键
builder.setView(edit);
builder.setPositiveButton("确认", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(context, "输入: " + edit.getText().toString(), Toast.LENGTH_SHORT).show();
}
});
builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(context, "点取消", Toast.LENGTH_SHORT).show();
}
});
4.设置用api并show弹
builder.setCancelable(true); //设置按钮否按返键取消,false则取消
AlertDialog dialog = builder.create(); //创建框
dialog.setCanceledOnTouchOutside(true); //设置弹框失焦点否隐藏,即点击屏蔽其否隐藏
dialog.show();
1.创建象框
AlertDialog.Builder builder = new Builder(context);
builder.setTitle("请输入"); //设置框标题
builder.setIcon(android.R.drawable.btn_star); //设置框标题前图标
2.创建EditText输入框
final EditText edit = new EditText(context);
3.输入框赋值给Dialog,并增加确定取消按键
builder.setView(edit);
builder.setPositiveButton("确认", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(context, "输入: " + edit.getText().toString(), Toast.LENGTH_SHORT).show();
}
});
builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(context, "点取消", Toast.LENGTH_SHORT).show();
}
});
4.设置用api并show弹
builder.setCancelable(true); //设置按钮否按返键取消,false则取消
AlertDialog dialog = builder.create(); //创建框
dialog.setCanceledOnTouchOutside(true); //设置弹框失焦点否隐藏,即点击屏蔽其否隐藏
dialog.show();
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询