gpt4 book ai didi

android - 一段时间后自动关闭窗口弹出。怎么做

转载 作者:太空狗 更新时间:2023-10-29 16:03:33 25 4
gpt4 key购买 nike

我试图在几秒钟后用一些时间计数器自动关闭膨胀的弹出窗口。我不知道与计数计时器(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 与自定义布局一起使用?参见 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com