Android仿微信进度弹出框的实现方法
MainActivity:
package com.ruru.dialogproject;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
public class MainActivity extends Activity implements Runnable {
LoadingDialog dialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.btn_name).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
dialog = new LoadingDialog(MainActivity.this);
dialog.setCanceledOnTouchOutside(false);
dialog.show();
new Thread(MainActivity.this).start();
}
});
}
public void run() {
try {
Thread.sleep();
dialog.dismiss();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
activity_main:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.ruru.dialogproject.MainActivity">
<Button
android:id="@+id/btn_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Hello World!" />
</RelativeLayout>
LoadingDialog:
package com.ruru.dialogproject;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.widget.LinearLayout;
import android.widget.TextView;
/**
* Created by 27c1 on 2017/1/4.
*/
public class LoadingDialog extends Dialog {
private TextView tv;
/**
* style很关键
*/
public LoadingDialog(Context context) {
super(context, R.style.loadingDialogStyle);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.dialog_loading);
tv = (TextView) findViewById(R.id.tv);
tv.setText("正在上传.....");
LinearLayout linearLayout = (LinearLayout) this.findViewById(R.id.LinearLayout);
linearLayout.getBackground().setAlpha();
}
}
dialog_loading:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/transparent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/LinearLayout"
android:layout_width="160dp"
android:layout_height="160dp"
android:background="@drawable/yuanjiao"
android:gravity="center"
android:orientation="vertical">
<ProgressBar
android:id="@+id/progressBar1"
style="?android:attr/progressBarStyleInverse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@android:color/transparent" />
<TextView
android:id="@+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingTop="10dp"
android:textColor="#fff" />
</LinearLayout>
</LinearLayout>
R.style.loadingDialogStyle:
<style name="loadingDialogStyle" parent="android:Theme.Dialog">
<item name="android:windowBackground">@android:color/transparent</item><!--设置dialog的背景-->
<item name="android:windowFrame">@null</item><!--Dialog的windowFrame框为无-->
<item name="android:windowNoTitle">true</item><!--是否显示title-->
<item name="android:windowIsFloating">true</item><!--是否浮现在activity之上-->
<item name="android:windowIsTranslucent">true</item><!--是否半透明-->
<item name="android:windowContentOverlay">@null</item><!--是否半透明-->
<item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item><!-- 对话框是否有遮盖 -->
<item name="android:backgroundDimEnabled">false</item><!--背景是否模糊显示-->
<item name="android:backgroundDimAmount">0.6</item><!--背景的灰度-->
</style>
drawable-yuanjiao:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#86222222" />
<corners
android:bottomLeftRadius="10dp"
android:bottomRightRadius="10dp"
android:topLeftRadius="10dp"
android:topRightRadius="10dp" />
</shape>
效果:
关于样式:
<item name="android:windowFrame">@null</item> :Dialog的windowFrame框为无
<item name="android:windowIsFloating">true</item>:是否浮现在activity之上
<item name="android:windowIsTranslucent">false</item>:是否半透明
<item name="android:windowNoTitle">true</item>:是否显示title
<item name="android:windowBackground">@drawable/dia_bg</item>:设置dialog的背景
<item name="android:backgroundDimEnabled">true</item>背景是否模糊显示
<item name="android:backgroundDimAmount">0.6</item>背景的灰度
Window attributes属性详解
Android仿微信进度弹出框的实现方法的更多相关文章
- Android仿ios底部弹出框效果
准备: public class ActionSheet { public interface OnActionSheetSelected { void onClick(int whichButton ...
- 【Android】各式各样的弹出框与对菜单键、返回键的监听
Android自带各式各样的弹出框.弹出框也是安卓主要的组件之中的一个.同一时候安卓程序能够对菜单键.返回键的监听.但在安卓4.0之后就禁止对Home键的屏蔽与监听,强制保留为系统守护按键.假设非要对 ...
- Android的几种弹出框
项目效果图: 新建一个项目,结构图如下所示: activity_main.xml: <?xml version="1.0" encoding="utf-8" ...
- ASP.NET中的几种弹出框提示基本方法
NET程序的开发过程中,常常需要和用户进行信息交互,对话框的出现将解决了这些问题,下面是本人对常用对话框使用的小结,希望对大家有所帮助 我们在.NET程序的开发过程中,常常需要和用户进行信息交互,比如 ...
- Android仿IOS底部弹出选择菜单ActionSheet
使用Dialog的实现方式,解决原ActionSheet使用Fragment实现而出现的部分手机取消按钮被遮盖的问题 java部分代码: import android.app.Dialog; impo ...
- ThickBox弹出框的使用方法
原文发布时间为:2009-08-22 -- 来源于本人的百度文章 [由搬家工具导入] 请访问:http://www.blueidea.com/articleimg/2007/12/5182/tickb ...
- android自定义弹出框样式实现
前言: 做项目时,感觉Android自带的弹出框样式比较丑,很多应用都是自己做的弹出框,这里也试着自己做了一个. 废话不说先上图片: 实现机制 1.先自定义一个弹出框的样式 2.自己实现CustomD ...
- 自动化测试-12.selenium的弹出框处理
前言 不是所有的弹出框都叫alert,在使用alert方法前,先要识别出到底是不是alert.先认清楚alert长什么样子,下次碰到了,就可以用对应方法解决. alert\confirm\prompt ...
- [js]uploadify结合jqueryUI弹出框上传,js中的冒出的bug,又被ie坑了
引言 最近在一个项目中,在用户列表中需要对给没有签名样本的个别用户上传签名的样本,就想到博客园中上传图片使用弹出框方式,博客园具体怎么实现的不知道,只是如果自己来弄,想到两个插件的结合使用,在弹出框中 ...
随机推荐
- Oracle SGA具体解释
SGA(SYSTEM Global Area )系统全局区 l 数据快速缓存 在Oracle进行数据处理的过程中,代价最昂贵的就是物理 I/O操作了.相同的数据从内存中得到要比从磁盘上读取快的多. 因 ...
- Restful技术
一.概述 Restful技术是一种架构风格(Representational State Transfer)表现层状态转化,而不是一种编程标准. 之前前后端混在一起,前端通过mapping映射找到后端 ...
- Light OJ 1317 Throwing Balls into the Baskets 概率DP
n个人 m个篮子 每一轮每一个人能够选m个篮子中一个扔球 扔中的概率都是p 求k轮后全部篮子里面球数量的期望值 依据全期望公式 进行一轮球数量的期望值为dp[1]*1+dp[2]*2+...+dp[ ...
- POJ 1496 POJ 1850 组合计数
Code Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 8256 Accepted: 3906 Description Tran ...
- 【iOS开发-54】案例学习:通过UIScrollView的缩放图片功能练习代理模式的详细实现
案例:(在模拟器中按住option键,点击鼠标就会出现缩放的手势) (1)在ViewController.m中: --缩放东西是UIScrollView除了滚动之外的还有一个功能,所以须要缩放的东西应 ...
- nyoj--1239--引水工程(最小生成树)
引水工程 时间限制:2000 ms | 内存限制:65535 KB 难度: 描述 南水北调工程是优化水资源配置.促进区域协调发展的基础性工程,是新中国成立以来投资额最大.涉及面最广的战略性工程,事 ...
- Vmware Workstation及Centos6.8 的安装
转自:http://www.mamicode.com/info-detail-1462939.html 一.什么是Vmware Workstation Vmware Workstation是Vmwar ...
- (五)api网关服务 zuul-路由
路由是微服务架构中必须的一部分,比如,“/” 可能映射到你的WEB程序上,”/api/users “可能映射到你的用户服务上,“/api/shop”可能映射到你的商品服务商.(注解:我理解这里的这几个 ...
- redis在项目中的使用(单机版、集群版)
1.下载jar包:jedis-2.6.2.jar 2.代码: JedisDao.java: package com.test.www.dao; public interface JedisDao { ...
- Windows phone解决GB2312编码问题
环境win8+vse for Windows phone 在网站http://encoding4silverlight.codeplex.com/上点击下载 之后有三个文件big5.bin,DBCSE ...