android对话框activity,Android使用Activity用作弹出式对话框

转载请表明出处:http://blog.csdn.net/lmj623565791/article/details/23116115

Android中可用于实现对话框的有Dialog,PopupWindow,Activity。

下面简单介绍下,Dialog比较方便,但是显示位置比较固定,有时不能满足我们的需求。

例子:(消除了背景)

@null

true

false

true

@android:color/black

@null

false

Dialog dialog = new Dialog(SetActivity.this, R.style.dialog);

dialog.setContentView(R.layout.test);

dialog.show();

PopupWindow可以通过showAtLocation设置显示位置,也可以通过ShowAsDropDown显示在某个View的相对位置,基本能满足我们的需求了。

下面介绍使用Activity作为弹出对话框,个人觉得好处有以下:

1、显示位置的设置,直接就是一个layout.xml随心所遇的感觉,可以实现在任何位置。

2、对对话框内控件的事件的处理,都独立出来在一个类中,调用的地方仅需要startActivity()就可以,这样可以使代码结构上更加清晰。

下面我们实现这个一个例子:

android对话框activity,Android使用Activity用作弹出式对话框_第1张图片

1、Activity的布局文件

android:layout_width="wrap_content"

android:layout_height="wrap_content"

>

android:onClick="tip"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentRight="true"

android:layout_alignParentTop=&#

你可能感兴趣的:(android对话框activity,Android使用Activity用作弹出式对话框)