如何使用Android仿微信网络加载弹出框

发布时间:2021-09-28 14:19:21 作者:小新
来源:亿速云 阅读:132

这篇文章给大家分享的是有关如何使用Android仿微信网络加载弹出框的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。

1. 自定义view的style样式

<resources>  <!-- Base application theme. -->  <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">    <!-- Customize your theme here. -->    <item name="colorPrimary">@color/colorPrimary</item>    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>    <item name="colorAccent">@color/colorAccent</item>  </style>  <!-- 自定义dialog的样式 -->  <style name="CustomDialog">    <item name="android:windowFrame">@null</item><!--边框-->    <item name="android:windowIsFloating">true</item><!--是否浮现在activity之上-->    <item name="android:windowIsTranslucent">false</item><!--半透明-->    <item name="android:windowNoTitle">true</item><!--无标题-->    <item name="android:windowBackground">@drawable/dialog_custom_bg</item><!--背景透明-->    <item name="android:backgroundDimEnabled">false</item><!--模糊-->    <item name="android:backgroundDimAmount">0.6</item>  </style></resources>

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

<shape xmlns:android="http://schemas.android.com/apk/res/android"  android:shape="rectangle">  <solid android:color="#ff333333" />  <corners android:radius="5dp" /></shape>

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

<?xml version="1.0" encoding="utf-8"?><rotate xmlns:android="http://schemas.android.com/apk/res/android"  android:drawable="@drawable/loading"  android:fromDegrees="0"  android:pivotX="50%"  android:pivotY="50%"  android:toDegrees="360"></rotate>

4.加载对话框的背景

<!-- 加载对话框布局 --><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  android:layout_width="wrap_content"  android:layout_height="wrap_content"  android:gravity="center"  android:orientation="horizontal"  android:padding="10dp">  <ProgressBar    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:indeterminateDrawable="@drawable/indeterminate_drawable"    android:indeterminateDuration="1800" />  <TextView    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" /></LinearLayout>

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();//消失

感谢各位的阅读!关于“如何使用Android仿微信网络加载弹出框”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!

推荐阅读:
  1. Android仿微信录制语音功能
  2. Android仿微信录音功能

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

android

上一篇:Ajax有哪些缓存机制

下一篇:iOS中如何使用WKWebView仿微信加载进度条

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》