我正试图自动关闭我的膨胀弹出窗口后,一些秒与一些时间计数器。我不知道怎么用计数计时器(5秒)。
LayoutInflater inflater = (LayoutInflater)screen.getSystemService(screen.LAYOUT_INFLATER_SERVICE);
layout = inflater.inflate(R.layout.log_viewer,null);
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setCancelable(true);
builder.setView(layout);
AlertDialog alertDialog = builder.create();
alertDialog.show();
Button btn0= (Button)layout.findViewById(R.id.btn0);
Button btn1= (Button)layout.findViewById(R.id.btn1);
Button btn2= (Button)layout.findViewById(R.id.btn2);
btn0.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent i =new Intent(Main_Activity.this,Act.class);
startActivity(i);
overridePendingTransition(R.anim.animation,R.anim.animation2);
}
});
btn1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent i =new Intent(Main_Activity.this,Activity2.class);
startActivity(i);
overridePendingTransition(R.anim.animation,R.anim.animation2);
}
});
btn2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent i =new Intent(Main_Activity.this,Activity1.class);
startActivity(i);
overridePendingTransition(R.anim.animation,R.anim.animation2);
}
});
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
Window window = alertDialog.getWindow();
lp.copyFrom(window.getAttributes());
lp.width = WindowManager.LayoutParams.MATCH_PARENT;
lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
window.setAttributes(lp);
最佳答案
您是否考虑在自定义布局中使用Toast
?请参见Android上的Toast documentation。
以开发者网站为例。
或者您可以使用Handler
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
// close your dialog
alertDialog.dismiss();
}
}, 10000); // 10,000 ms delay
关于android - 一段时间后,自动关闭窗口弹出。怎么做,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22878787/