欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

Android仿微信进度弹出框的实现方法

程序员文章站 2024-02-24 08:48:30
mainactivity: package com.ruru.dialogproject; import android.app.activity; im...

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(5000); 
   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(210); 
 } 
} 

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>

效果:

Android仿微信进度弹出框的实现方法

关于样式:

<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仿微信进度弹出框的实现方法

颜色为:#393939

以上所述是小编给大家介绍的android仿微信进度弹出框效果,希望对大家有所帮助