溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

如何使用Android仿微信網絡加載彈出框

發布時間:2021-09-28 14:19:21 來源:億速云 閱讀:187 作者:小新 欄目:編程語言

這篇文章給大家分享的是有關如何使用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仿微信網絡加載彈出框”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,讓大家可以學到更多知識,如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女