Android对话框显示后自动消失
16lz
2021-12-04
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(安卓)Service实现闹钟
- android之AlerDialog
- Android实现弹出Toast提示
- eclipse运行android时Console最后提示Done!不运行程序
- Android对话框实例-注册对话框
- Android漂亮的Help提示框
- androidの自定义加载对话框ProgressDialog