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

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

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

例子:(消除了背景)

<resources>
<style name="dialog" parent="@android:style/Theme.Dialog">
<item name="android:windowFrame">@null</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowIsTranslucent">false</item>
<item name="android:windowNoTitle">true</item>
<item name="android:background">@android:color/black</item>
<item name="android:windowBackground">@null</item>
<item name="android:backgroundDimEnabled">false</item>
</style>
</resources>
 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()就可以,这样可以使代码结构上更加清晰。

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

1、Activity的布局文件

<?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"
> <LinearLayout
android:onClick="tip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginTop="46dp"
android:background="@drawable/title_function_bg"
android:orientation="vertical" > <TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:drawableLeft="@drawable/mm_title_btn_compose_normal"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="发起聊天"
android:textColor="#fff"
android:textSize="20sp" /> <TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:drawableLeft="@drawable/mm_title_btn_keyboard_normal"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="登录网页版"
android:textColor="#fff"
android:textSize="20sp" /> <TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:drawableLeft="@drawable/mm_title_btn_qrcode_normal"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="扫一扫"
android:textColor="#fff"
android:textSize="20sp" /> <TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:drawableLeft="@drawable/mm_title_btn_receiver_normal"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="听筒模式"
android:textColor="#fff"
android:textSize="20sp" />
</LinearLayout> </RelativeLayout>

2、在style.xml中定义一个theme(背景透明,无标题,动画效果),一般Activity默认动画效果右进右出,我们可以覆盖。

   <style name="MyDialogTopRight">
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowAnimationStyle">@style/Anim_scale</item>
</style>

动画效果:

    <style name="Anim_scale" parent="@android:style/Animation.Activity">
<item name="android:activityOpenEnterAnimation">@anim/scale_in</item>
<item name="android:activityOpenExitAnimation">@anim/scale_out</item>
<item name="android:activityCloseEnterAnimation">@anim/scale_in</item>
<item name="android:activityCloseExitAnimation">@anim/scale_out</item>
</style>

3、在需要使用的地方直接startActity()就可以了

Intent intent = new Intent(context, MainWeixinTitleRightActivity.class);
startActivity(intent);

最终效果:

源码下载,点击这里

Android使用Activity用作弹出式对话框的更多相关文章

  1. 【转】PyQt弹出式对话框的常用方法及标准按钮类型

    pyQt之弹出式对话框(QMessageBox)的常用方法及标准按钮类型 一.控件说明 QMessageBox是一种通用的弹出式对话框,用于显示消息,允许用户通过单击不同的标准按钮对消息进行反馈,且每 ...

  2. xamarin.android 实现 Activity 底部弹出对话框菜单

    Resources/drawable 下新增如下文件: push_bottom_in.xml <?xml version="1.0" encoding="utf-8 ...

  3. android弹出式菜单、弹出式对话框、弹出式窗口

    http://www.open-open.com/lib/view/open1389767042601.html http://www.open-open.com/lib/view/open13321 ...

  4. android 闹钟提醒并且在锁屏下弹出Dialog对话框并播放铃声和震动

    android 闹钟提醒并且在锁屏下弹出Dialog对话框并播放铃声和震动            1.先简单设置一个闹钟提醒事件: //设置闹钟 mSetting.setOnClickListener ...

  5. Android 如何解决dialog弹出时无法捕捉Activity的back事件

    Android 如何解决dialog弹出时无法捕捉Activity的back事件 在一些情况下,我们需要捕捉back键事件,然后在捕捉到的事件里写入我们需要进行的处理,通常可以采用下面三种办法捕捉到b ...

  6. 20150629_Andriod_06_插入_删除_弹出式操作数据

    Fr_06_view_s6 --> activity_f6_insert              --> activity_f7__delete ******************** ...

  7. web开发实战--弹出式富文本编辑器的实现思路和踩过的坑

    前言: 和弟弟合作, 一起整了个智慧屋的小web站点, 里面包含了很多经典的智力和推理题. 其实该站点从技术层面来分析的话, 也算一个信息发布站点. 因此在该网站的后台运营中, 富文本的编辑器显得尤为 ...

  8. PropertyGrid—为复杂属性提供下拉式编辑框和弹出式编辑框

    零.引言 PropertyGrid中我们经常看到一些下拉式的编辑方式(Color属性)和弹出式编辑框(字体),这些都是为一些复杂的属性提供的编辑方式,本文主要说明如何实现这样的编辑方式. 一.为属性提 ...

  9. 【Android】创建Popwindow弹出菜单的两种方式

    方法一的Activity package com.app.test02; import android.app.Activity; import android.os.Bundle; import a ...

随机推荐

  1. 让qt应用程序支持触摸

    一.设备驱动 我的触摸屏是usb接口的 可以参考下这2篇文件 http://blog.csdn.net/paomadi/article/details/8754783 usb触摸屏 http://bl ...

  2. MySQLdb的安装与使用

    一.安装 安装已编译版本号(此方法简便快捷): http://www.codegood.com/downloads 依据自己系统下载,双击安装,搞定 然后import MySQLdb.查看是否成功 我 ...

  3. [置顶] github简单使用

    git的介绍可以看这里   http://zh.wikipedia.org/wiki/GitHub 安装和使用参考的这个    http://www.cnblogs.com/cocowool/arch ...

  4. iphone开发中数据持久化之——模型对象归档(二)

    在Cocoa世界中,术语“归档”是指另一种形式的序列化,它可以实现对任何对象的序列化.使用对模型对象进行归档的技术可以轻松将复杂的对象写入文件,然后再从中读取它们.只要在类中实现的每个属性都是标量(如 ...

  5. spring Annotation 组分注塑

    spring 注意分类 启动spring自己主动扫描功能 <context:component-scan/> 1.@Repository: 它用于将数据訪问层 (DAO 层 ) 的类标识为 ...

  6. ueditor编辑文章时候,复制粘贴内容,原来的图片不能显示

    ueditor编辑文章时候.当现有文章有图片的时候, 再复制粘贴文本进去的时候.里面的图片就不能显示了, 编辑器查看文章Html代码,图片路径显示为:src="http://localhos ...

  7. hdu3062(two-sat)

    传送门:Party 题意:有n对夫妻被邀请参加一个聚会,因为场地的问题,每对夫妻中只有1人可以列席.在2n 个人中,某些人之间有着很大的矛盾(当然夫妻之间是没有矛盾的),有矛盾的2个人是不会同时出现在 ...

  8. https原理及tomcat配置https方法

    一. 什么是HTTPS 在说HTTPS之前先说说什么是HTTP,HTTP就是我们平时浏览网页时候使用的一种协议.HTTP协议传输的数据都是未加密的,也就是明文的,因此使用HTTP协议传输隐私信息非常不 ...

  9. 在Windows下使用Hexo+GithubPage搭建博客的过程

    1.安装Node.js 下载地址:传送门 去 node.js 官网下载相应版本,进行安装即可. 可以通过node -v的命令来测试NodeJS是否安装成功 2.安装Git 下载地址:传送门 去 Git ...

  10. Redis集群明细文档(转)

    相信很多用过Redis的同学都知道,Redis目前版本是没有提供集群功能的,只能单打独斗.如果要实现多台Redis同时提供服务只能通过客户端自身去实现.目前根据文档已经看到Redis正在开发集群功能, ...