android 仿微信加载框,Android仿微信网络加载弹出框

本文实例为大家分享了Android仿微信网络加载弹出框的具体代码,供大家参考,具体内容如下

没有饿了么的动画效果好看,但是,特别适用,拿来就用!

看一下效果图

8d6245629aed362dac98c5b6b7822f81.gif

图片素材

b06b17fa8f41c4e679ad1aa84cb985b9.png

好了,其实很简单,就是一个自定义Dialog的控件而已

1. 自定义view的style样式

@color/colorPrimary

@color/colorPrimaryDark

@color/colorAccent

@null

true

false

true

@drawable/dialog_custom_bg

false

0.6

2.dialog_custom_bg 加载动画shape背景图(drawable文件夹下)

android:shape="rectangle">

3.indeterminate_drawable 进度条模糊背景图(drawable文件夹下)

android:drawable="@drawable/loading"

android:fromDegrees="0"

android:pivotX="50%"

android:pivotY="50%"

android:toDegrees="360">

4.加载对话框的背景

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:gravity="center"

android:orientation="horizontal"

android:padding="10dp">

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:indeterminateDrawable="@drawable/indeterminate_drawable"

android:indeterminateDuration="1800" />

android:id="@+id/tvcontent"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:paddingLeft="10dp"

android:paddingRight="10dp"

android:text="加载中"

android:textColor="#ffffff"

android:textSize="14sp" />

5.CustomDialog自定义控件

public class CustomDialog extends Dialog {

private String content;

public CustomDialog(Context context, String content) {

super(context, R.style.CustomDialog);

this.content=content;

initView();

}

@Override

public boolean onKeyDown(int keyCode, KeyEvent event) {

switch (keyCode){

case KeyEvent.KEYCODE_BACK:

if(CustomDialog.this.isShowing())

CustomDialog.this.dismiss();

break;

}

return true;

}

private void initView(){

setContentView(R.layout.dialog_view);

((TextView)findViewById(R.id.tvcontent)).setText(content);

setCanceledOnTouchOutside(true);

WindowManager.LayoutParams attributes = getWindow().getAttributes();

attributes.alpha=0.8f;

getWindow().setAttributes(attributes);

setCancelable(false);

}

}

6.Activity中直接调用

CustomDialog customDialog = new CustomDialog(this, "正在加载...");

customDialog.show();//显示,显示时页面不可点击,只能点击返回

customDialog.dismiss();//消失

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持找一找教程网。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值