Android对话框显示后自动消失
16lz
2021-01-23
package com.example.dialog_1;import android.app.Activity;import android.app.AlertDialog;import android.os.Bundle;import android.os.Handler;public class MainActivity extends Activity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);// ///弹出是否添加城市的 对话框final AlertDialog alert = new AlertDialog.Builder(MainActivity.this).create();alert.setTitle("悟空提示:");alert.setMessage("您是第8位用户");alert.show();new Handler().postDelayed(new Runnable() {@Overridepublic void run() {alert.dismiss();}}, 2000);}////onCreate}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="${relativePackage}.${activityClass}" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" /></RelativeLayout>
网上看了一下写的很复杂,我这是简便的方法,
打开就显示2s,后自动消失
更多相关文章
- Android AlertDialog工具类 实现对话框回调
- Android对话框实例-注册对话框
- androidの自定义加载对话框ProgressDialog
- android 透明对话框
- 修改 ActivityManagerService.java 去掉 android 系统报错和程序
- Android自定义Dialog对话框
- android 对话框AlertDialog
- android弹出对话框大全