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 {
@Override
protected 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() {
@Override
public 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,后自动消失
欢迎关注我的公众号