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 { 
 CustomDialog dialog; 
 @Override
 protected void onCreate(Bundle savedInstanceState) { 
  super.onCreate(savedInstanceState); 
  setContentView(R.layout.activity_main); 
  findViewById(R.id.btn_submit).setOnClickListener(new View.OnClickListener() { 
   @Override
   public void onClick(View view) { 
    dialog = new CustomDialog(MainActivity.this, "操作成功!",true); 
    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_submit"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:text="Hello World!" /> 
</RelativeLayout>
自定义 CustomDialog:
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 Yyt on 2019/12/17. 
 */
public class CustomDialog extends Dialog { 
	  private TextView mTvTip;
	  private boolean isRight;
	  private String msg;
	  private ImageView mIvWxRight;
	  private ImageView mIvWxRrror; 
 	/**
     * style很关键
     */
    public CustomDialog(Context context, String msg, Boolean isRight) {
        super(context, R.style.customDialogStyle);
        this.isRight = isRight;
        this.msg = msg;
    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.custom_dialog);

        mTvTip = (TextView) findViewById(R.id.tv_tip);
        mIvWxRight = (ImageView)findViewById(R.id.iv_wx_right);
        mIvWxRrror = (ImageView)findViewById(R.id.iv_wx_error);
        mTvTip.setText(msg);
        if (isRight){
            mIvWxRight.setVisibility(View.VISIBLE);
        }else {
            mIvWxRrror.setVisibility(View.VISIBLE);
        }
        LinearLayout linearLayout = (LinearLayout) this.findViewById(R.id.LinearLayout);
        linearLayout.getBackground().setAlpha(210);
    }
}
custom_dialog:
<?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/dialog_custom"
        android:gravity="center"
        android:orientation="vertical">
        <ProgressBar
            android:id="@+id/progressBar"
            style="?android:attr/progressBarStyleInverse"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:background="@android:color/transparent"
            android:visibility="gone"/>

        <ImageView
            android:id="@+id/iv_wx_right"
            android:layout_width="44dp"
            android:layout_height="44dp"
            android:src="@drawable/icon_wx_right"
            android:visibility="gone"/>

        <ImageView
            android:id="@+id/iv_wx_error"
            android:layout_width="44dp"
            android:layout_height="44dp"
            android:src="@drawable/icon_wx_error"
            android:visibility="gone"/>

        <TextView
            android:id="@+id/tv_tip"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:paddingTop="10dp"
            android:text="123"
            android:textSize="16sp"
            android:textColor="#fff" />
    </LinearLayout>
</LinearLayout>
R.style.customDialogStyle:
// An highlighted block
<style name="customDialogStyle" 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-corner:
// An highlighted block
<?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>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值