MainActivity:

  1. package com.ruru.dialogproject;
  2. import android.app.Activity;
  3. import android.os.Bundle;
  4. import android.view.View;
  5. public class MainActivity extends Activity implements Runnable {
  6. LoadingDialog dialog;
  7. @Override
  8. protected void onCreate(Bundle savedInstanceState) {
  9. super.onCreate(savedInstanceState);
  10. setContentView(R.layout.activity_main);
  11. findViewById(R.id.btn_name).setOnClickListener(new View.OnClickListener() {
  12. @Override
  13. public void onClick(View view) {
  14. dialog = new LoadingDialog(MainActivity.this);
  15. dialog.setCanceledOnTouchOutside(false);
  16. dialog.show();
  17. new Thread(MainActivity.this).start();
  18. }
  19. });
  20. }
  21. public void run() {
  22. try {
  23. Thread.sleep();
  24. dialog.dismiss();
  25. } catch (InterruptedException e) {
  26. e.printStackTrace();
  27. }
  28. }
  29. }

activity_main:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. xmlns:tools="http://schemas.android.com/tools"
  4. android:id="@+id/activity_main"
  5. android:layout_width="match_parent"
  6. android:layout_height="match_parent"
  7. tools:context="com.ruru.dialogproject.MainActivity">
  8. <Button
  9. android:id="@+id/btn_name"
  10. android:layout_width="match_parent"
  11. android:layout_height="wrap_content"
  12. android:text="Hello World!" />
  13. </RelativeLayout>

LoadingDialog:

  1. package com.ruru.dialogproject;
  2. import android.app.Dialog;
  3. import android.content.Context;
  4. import android.os.Bundle;
  5. import android.widget.LinearLayout;
  6. import android.widget.TextView;
  7. /**
  8. * Created by 27c1 on 2017/1/4.
  9. */
  10. public class LoadingDialog extends Dialog {
  11. private TextView tv;
  12. /**
  13. * style很关键
  14. */
  15. public LoadingDialog(Context context) {
  16. super(context, R.style.loadingDialogStyle);
  17. }
  18. @Override
  19. protected void onCreate(Bundle savedInstanceState) {
  20. super.onCreate(savedInstanceState);
  21. setContentView(R.layout.dialog_loading);
  22. tv = (TextView) findViewById(R.id.tv);
  23. tv.setText("正在上传.....");
  24. LinearLayout linearLayout = (LinearLayout) this.findViewById(R.id.LinearLayout);
  25. linearLayout.getBackground().setAlpha();
  26. }
  27. }

dialog_loading:

  1.  
  2. <?xml version="1.0" encoding="utf-8"?>
  3. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  4. android:layout_width="fill_parent"
  5. android:layout_height="fill_parent"
  6. android:background="@android:color/transparent"
  7. android:orientation="vertical">
  8. <LinearLayout
  9. android:id="@+id/LinearLayout"
  10. android:layout_width="160dp"
  11. android:layout_height="160dp"
  12. android:background="@drawable/yuanjiao"
  13. android:gravity="center"
  14. android:orientation="vertical">
  15. <ProgressBar
  16. android:id="@+id/progressBar1"
  17. style="?android:attr/progressBarStyleInverse"
  18. android:layout_width="wrap_content"
  19. android:layout_height="wrap_content"
  20. android:layout_gravity="center"
  21. android:background="@android:color/transparent" />
  22. <TextView
  23. android:id="@+id/tv"
  24. android:layout_width="wrap_content"
  25. android:layout_height="wrap_content"
  26. android:layout_gravity="center"
  27. android:paddingTop="10dp"
  28. android:textColor="#fff" />
  29. </LinearLayout>
  30. </LinearLayout>

R.style.loadingDialogStyle:

  1. <style name="loadingDialogStyle" parent="android:Theme.Dialog">
  2. <item name="android:windowBackground">@android:color/transparent</item><!--设置dialog的背景-->
  3. <item name="android:windowFrame">@null</item><!--Dialog的windowFrame框为无-->
  4. <item name="android:windowNoTitle">true</item><!--是否显示title-->
  5. <item name="android:windowIsFloating">true</item><!--是否浮现在activity之上-->
  6. <item name="android:windowIsTranslucent">true</item><!--是否半透明-->
  7. <item name="android:windowContentOverlay">@null</item><!--是否半透明-->
  8. <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item><!-- 对话框是否有遮盖 -->
  9. <item name="android:backgroundDimEnabled">false</item><!--背景是否模糊显示-->
  10. <item name="android:backgroundDimAmount">0.6</item><!--背景的灰度-->
  11. </style>

drawable-yuanjiao:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <shape xmlns:android="http://schemas.android.com/apk/res/android">
  3. <solid android:color="#86222222" />
  4. <corners
  5. android:bottomLeftRadius="10dp"
  6. android:bottomRightRadius="10dp"
  7. android:topLeftRadius="10dp"
  8. android:topRightRadius="10dp" />
  9. </shape>

效果:

关于样式:

  1. <item name="android:windowFrame">@null</item> :Dialog的windowFrame框为无
  2. <item name="android:windowIsFloating">true</item>:是否浮现在activity之上
  3. <item name="android:windowIsTranslucent">false</item>:是否半透明
  4. <item name="android:windowNoTitle">true</item>:是否显示title
  5. <item name="android:windowBackground">@drawable/dia_bg</item>:设置dialog的背景
  6. <item name="android:backgroundDimEnabled">true</item>背景是否模糊显示
  7. <item name="android:backgroundDimAmount">0.6</item>背景的灰度

Window attributes属性详解

Android仿微信进度弹出框的实现方法的更多相关文章

  1. Android仿ios底部弹出框效果

    准备: public class ActionSheet { public interface OnActionSheetSelected { void onClick(int whichButton ...

  2. 【Android】各式各样的弹出框与对菜单键、返回键的监听

    Android自带各式各样的弹出框.弹出框也是安卓主要的组件之中的一个.同一时候安卓程序能够对菜单键.返回键的监听.但在安卓4.0之后就禁止对Home键的屏蔽与监听,强制保留为系统守护按键.假设非要对 ...

  3. Android的几种弹出框

    项目效果图: 新建一个项目,结构图如下所示: activity_main.xml: <?xml version="1.0" encoding="utf-8" ...

  4. ASP.NET中的几种弹出框提示基本方法

    NET程序的开发过程中,常常需要和用户进行信息交互,对话框的出现将解决了这些问题,下面是本人对常用对话框使用的小结,希望对大家有所帮助 我们在.NET程序的开发过程中,常常需要和用户进行信息交互,比如 ...

  5. Android仿IOS底部弹出选择菜单ActionSheet

    使用Dialog的实现方式,解决原ActionSheet使用Fragment实现而出现的部分手机取消按钮被遮盖的问题 java部分代码: import android.app.Dialog; impo ...

  6. ThickBox弹出框的使用方法

    原文发布时间为:2009-08-22 -- 来源于本人的百度文章 [由搬家工具导入] 请访问:http://www.blueidea.com/articleimg/2007/12/5182/tickb ...

  7. android自定义弹出框样式实现

    前言: 做项目时,感觉Android自带的弹出框样式比较丑,很多应用都是自己做的弹出框,这里也试着自己做了一个. 废话不说先上图片: 实现机制 1.先自定义一个弹出框的样式 2.自己实现CustomD ...

  8. 自动化测试-12.selenium的弹出框处理

    前言 不是所有的弹出框都叫alert,在使用alert方法前,先要识别出到底是不是alert.先认清楚alert长什么样子,下次碰到了,就可以用对应方法解决. alert\confirm\prompt ...

  9. [js]uploadify结合jqueryUI弹出框上传,js中的冒出的bug,又被ie坑了

    引言 最近在一个项目中,在用户列表中需要对给没有签名样本的个别用户上传签名的样本,就想到博客园中上传图片使用弹出框方式,博客园具体怎么实现的不知道,只是如果自己来弄,想到两个插件的结合使用,在弹出框中 ...

随机推荐

  1. 基于Dragon Board410c 的智能机器人预研-语音识别及定位

    转自:http://www.csdn.net/article/a/2016-01-06/15833642 一.前言 机器人是一种可编程和多功能的.用来搬运材料.零件.工具的操作机,智能机器人则是一个在 ...

  2. Android 开发之集成百度地图的定位与地图展示

    app 应用中,大多数应用都具有定位功能,百度定位就成了开发人员的集成定位功能的首选,近期也在做定位功能,可是发现百度真是个大坑啊, sdk 命名更新了,相关代码却不更新,害得我花费了非常长时间来研究 ...

  3. apiCloud中openFrameGroup传参

    apiCloud中openFrameGroup传参 1.无效的 api.openFrameGroup({ // 打开 frame 组 name: 'group', scrollEnabled: fal ...

  4. 4K 对齐与固态硬盘检测工具

    0. 硬盘扇区 当前电脑传统机械硬盘的每个扇区一般大小为 512 字节(512B):当使用某一文件系统将硬盘格式化时,文件系统会将硬盘扇区.磁道与柱面统计整理并定义一个簇为多少扇区方便快速存储. 现时 ...

  5. Array数组的排序与二分查字法

    import java.util.Arrays; public class sort { public static void main(String[] args) { // TODO 自动生成的方 ...

  6. (转载) android快速搭建项目积累

    android快速搭建项目积累 2016-04-05 20:07 519人阅读 评论(0) 收藏 举报  分类: android优化(8)   Rx技术(5)  版权声明:本文为博主原创文章,未经博主 ...

  7. android全屏去掉title栏的多种实现方法

    android全屏去掉title栏的多种实现方法 作者: 字体:[增加 减小] 类型:转载 时间:2013-02-18我要评论 android全屏去掉title栏包括以下几个部分:实现应用中的所有ac ...

  8. JS自定义全局Error

    <script> ///自定义错误 onerror=handleErr; function handleErr(msg,url,l) { var txt=""; txt ...

  9. CodeForces-766D Mahmoud and a Dictionary 并查集 维护同类不同类元素集合

    题目链接:https://cn.vjudge.net/problem/CodeForces-766D 题意 写词典,有些词是同义词,有些是反义词,还有没关系的词 首先输入两个词,需要判断是同义还是是反 ...

  10. layui框架下的摸索与学习

    一.table表格内的查询  1.单个条件查询: 主要代码: <%-- Created by IntelliJ IDEA. User: Administrator Date: 2019/1/14 ...