//自定义dilog
public void showDialog() {
//1.创建一个Dialog对象,如果是AlertDialog对象的话,弹出的自定义布局四周会有一些阴影,效果不好
mDialog = new Dialog(this);
//去除标题栏
mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
//2.填充布局
LayoutInflater inflater = LayoutInflater.from(this);
View dialogView = inflater.inflate(R.layout.view_dialog, null);
//将自定义布局设置进去
mDialog.setContentView(dialogView);
//3.设置指定的宽高,如果不设置的话,弹出的对话框可能不会显示全整个布局,当然在布局中写死宽高也可以
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
Window window = mDialog.getWindow();
lp.copyFrom(window.getAttributes());
lp.width = WindowManager.LayoutParams.MATCH_PARENT;
lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
//注意要在Dialog show之后,再将宽高属性设置进去,才有效果
mDialog.show();
window.setAttributes(lp);
//设置点击其它地方不让消失弹窗
// mDialog.setCancelable(false);
initDialogView(dialogView);
}
//顶上状态栏
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
}
//获取状态栏高度
Resources resources = getResources();
int resourceId = resources.getIdentifier("status_bar_height", "dimen","android");
int height = resources.getDimensionPixelSize(resourceId);
View view=rootView.findViewById(R.id.vi);
ViewGroup.LayoutParams params = view.getLayoutParams();
params.height = height;
view.setLayoutParams(params);
//定时器
handler.postDelayed(runnable, 0);
Handler handler = new Handler();
Runnable runnable = new Runnable() {
@Override
public void run() {
// handler自带方法实现定时器
try {
if (time < 1) {
time = MaxTime;
setBtn(TYPE1);
} else {
huoqu.setText(String.format(Locale.CHINA, "%ds", time--));
handler.postDelayed(this, 1000);
}
} catch (Exception e) {
e.printStackTrace();
}
}
};
Dialog
最新推荐文章于 2024-04-15 14:38:30 发布