如何在Android应用程序启动时加载弹出窗口?的onCreate()? [英] How to load popup window on android application startup? onCreate()?
问题描述
我是新android开发,我想请教如何在Android应用程序启动时加载弹出窗口?的onCreate()?
I am new to android development and i want to ask how to load popup window on android application startup? onCreate()?
我看过很多例子,但没有一个人捂住了我的需求。有没有办法来加载一个弹出窗口,在应用程序启动?
I have seen many examples but no one covered my needs. Is there a way to load a popup window on application start?
感谢您
推荐答案
要做到这一点,最好的地方是在你活动的在onStart
方法。从本质上讲,我们需要:
The best place to do this is in the onStart
method of your Activity. Essentially, we need to:
- 获取一个新的对话框,并指定你想要的XML布局。
- 填写其他选项,包括code运行时在对话框上的按钮,用户点击(在这种情况下,只需关闭该对话框)。
- 显示该对话框。
下面是一个简单的例子,但也有很多的选择缴费。欲了解更多信息,请参见 http://developer.android.com/reference/android/应用程序/ Dialog.html 。
Here's a simple example, but there are lots of options avaiable. For more information, see http://developer.android.com/reference/android/app/Dialog.html.
RES /布局/ dialog.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView android:text="hello, world"
android:id="@+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<Button android:id="@+id/Button01"
android:layout_below="@id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="OK" />
</RelativeLayout>
在你的活动
@Override
protected void onStart()
{
super.onStart();
final Dialog dialog = new Dialog(this);
dialog.setContentView(R.layout.dialog);
dialog.setTitle("Dialog box");
Button button = (Button) dialog.findViewById(R.id.Button01);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
dialog.dismiss();
}
});
dialog.show();
}
这篇关于如何在Android应用程序启动时加载弹出窗口?的onCreate()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!