欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android仿微信網(wǎng)絡(luò)加載彈出框

 更新時(shí)間:2019年06月15日 15:44:36   作者:AND_Devil  
這篇文章主要為大家詳細(xì)介紹了Android仿微信網(wǎng)絡(luò)加載彈出框,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Android仿微信網(wǎng)絡(luò)加載彈出框的具體代碼,供大家參考,具體內(nèi)容如下

沒有餓了么的動(dòng)畫效果好看,但是,特別適用,拿來就用!

看一下效果圖

圖片素材

好了,其實(shí)很簡單,就是一個(gè)自定義Dialog的控件而已

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><!--是否浮現(xiàn)在activity之上-->
    <item name="android:windowIsTranslucent">false</item><!--半透明-->
    <item name="android:windowNoTitle">true</item><!--無標(biāo)題-->
    <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 加載動(dòng)畫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 進(jìn)度條模糊背景圖(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中直接調(diào)用

CustomDialog customDialog = new CustomDialog(this, "正在加載...");
customDialog.show();//顯示,顯示時(shí)頁面不可點(diǎn)擊,只能點(diǎn)擊返回
customDialog.dismiss();//消失

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論