日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

Android开发之自定义菊花进度条对话框

發布時間:2023/12/15 Android 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Android开发之自定义菊花进度条对话框 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

先看下效果:



寫個進度條調用類:

package com.xiayiye.yhsh.flowerdialog;import android.app.Activity; import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface;/*** 網絡請求加載對話框以及普通的alertDialog*/ public class DialogUtils {private Context mContext;private LoadingDialog loadingDialog;public DialogUtils(Context context) {this.mContext = context;}/*** 顯示菊花以及菊花下方的文字提示,點擊外部不可取消,點擊返回可以取消* 不接收回調接收回調*/public void showLoadingWithLabel(String text) {loadingDialog = LoadingDialog.create(mContext).setLabel(text).show();}/*** 顯示菊花以及菊花下方的文字提示,點擊外部不可取消,點擊返回可以取消* 接收回調*/public void showLoadingWithLabel(String text, DialogInterface.OnCancelListener onCancelListener) {loadingDialog = LoadingDialog.create(mContext).setLabel(text).setCancellableListener(onCancelListener).show();}/*** @Param cancelable 設置為false 返回按鈕不可用 若為true 直接調用{@link #showLoadingWithLabel}的監聽方法* 顯示菊花以及菊花下方的文字提示,點擊外部不可取消,點擊返回可以取消* 不接收回調接收回調*/public void showLoadingWithLabel(String text, boolean cancelable) {loadingDialog = LoadingDialog.create(mContext).setLabel(text).setCancellable(cancelable).show();}/*** 僅顯示一個菊花 不接收取消回調* 默認點擊外部不可取消 ,點擊返回按鈕可以dismiss*/public void showLoading() {loadingDialog = LoadingDialog.create(mContext).show();}/*** 僅顯示一個菊花 并且有 cancel回調* 默認點擊外部不可取消 ,點擊返回按鈕可以dismiss*/public void showLoading(DialogInterface.OnCancelListener onCancelListener) {loadingDialog = LoadingDialog.create(mContext).setCancellableListener(onCancelListener).show();}/*** @Param cancelable 設置為false 返回按鈕不可用 若為true 直接調用{@link #showLoading}的監聽方法* 顯示菊花,點擊外部不可取消* 不接收回調*/public void showLoading(boolean cancelable) {loadingDialog = LoadingDialog.create(mContext).setCancellable(cancelable).show();}/*** dismiss*/public void dismissLoading() {if (loadingDialog!=null)loadingDialog.dismiss();}/*** 無title 一個positivebutton 點擊外部以及返回按鈕均不可取消* 點擊button消失** @param message* @param textPositiveButton* @param onDismissListener null時不監聽dismiss*/public void showAlertDialog(String message, String textPositiveButton, DialogInterface.OnDismissListener onDismissListener) {if(!((Activity) mContext).isFinishing()) {new AlertDialog.Builder(mContext).setCancelable(false).setMessage(message).setPositiveButton(textPositiveButton, new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {dialog.dismiss();}}).setOnDismissListener(onDismissListener).show();}}}



2.工具類里面涉及到的LoadingDialog類如下:

package com.xiayiye.yhsh.flowerdialog;import android.annotation.SuppressLint; import android.app.Dialog; import android.content.Context; import android.content.DialogInterface; import android.graphics.Color; import android.graphics.drawable.ColorDrawable; import android.os.Bundle; import android.view.Gravity; import android.view.View; import android.view.ViewGroup; import android.view.Window; import android.view.WindowManager; import android.widget.FrameLayout; import android.widget.TextView;public class LoadingDialog {private ProgressDialog mProgressDialog;private float mDimAmount;private int mWindowColor;private float mCornerRadius;public LoadingDialog(Context context) {mProgressDialog = new ProgressDialog(context);mDimAmount = 0;mWindowColor = context.getResources().getColor(R.color.colorLoadingProgressBg);mCornerRadius = 10;View view = new SpinView(context);mProgressDialog.setView(view);}public static LoadingDialog create(Context context) {return new LoadingDialog(context);}/*** 設置背景透明度** @param dimAmount* @return*/public LoadingDialog setDimAmount(float dimAmount) {if (dimAmount >= 0 && dimAmount <= 1) {mDimAmount = dimAmount;}return this;}/*** @param color ARGB color* @return Current HUD* @deprecated As of release 1.1.0, replaced by {@link #setBackgroundColor(int)}*/@Deprecatedpublic LoadingDialog setWindowColor(int color) {mWindowColor = color;return this;}/*** Specify the HUD background color** @param color ARGB color* @return Current HUD*/public LoadingDialog setBackgroundColor(int color) {mWindowColor = color;return this;}/*** Specify corner radius of the HUD (default is 10)** @param radius Corner radius in dp* @return Current HUD*/public LoadingDialog setCornerRadius(float radius) {mCornerRadius = radius;return this;}/*** 設置下方文字 默認白色** @param label* @return*/public LoadingDialog setLabel(String label) {mProgressDialog.setLabel(label);return this;}/*** 設置文字及其顏色** @param label* @param color* @return*/public LoadingDialog setLabel(String label, int color) {mProgressDialog.setLabel(label, color);return this;}/*** Provide a custom view to be displayed.** @param view Must not be null* @return Current HUD*/public LoadingDialog setCustomView(View view) {if (view != null) {mProgressDialog.setView(view);} else {throw new RuntimeException("Custom view must not be null!");}return this;}/*** 設置是否可取消** @param isCancellable* @return*/public LoadingDialog setCancellable(boolean isCancellable) {mProgressDialog.setCancelable(isCancellable);mProgressDialog.setOnCancelListener(null);return this;}/*** 設置取消監聽** @param listener* @return*/public LoadingDialog setCancellableListener(DialogInterface.OnCancelListener listener) {mProgressDialog.setCancelable(null != listener);mProgressDialog.setOnCancelListener(listener);return this;}public LoadingDialog show() {if (!isShowing()) {mProgressDialog.show();}return this;}public boolean isShowing() {return mProgressDialog != null && mProgressDialog.isShowing();}public void dismiss() {if (mProgressDialog != null && mProgressDialog.isShowing()) {mProgressDialog.dismiss();}}private class ProgressDialog extends Dialog {private View mView;private TextView mLabelText;private String mLabel;private FrameLayout mCustomViewContainer;private BackgroundLayout mBackgroundLayout;private int mLabelColor = Color.WHITE;public ProgressDialog(Context context) {super(context);}@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);requestWindowFeature(Window.FEATURE_NO_TITLE);setContentView(R.layout.loading_progress_layout);Window window = getWindow();window.setBackgroundDrawable(new ColorDrawable(0));window.addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);WindowManager.LayoutParams layoutParams = window.getAttributes();layoutParams.dimAmount = mDimAmount;layoutParams.gravity = Gravity.CENTER;window.setAttributes(layoutParams);setCanceledOnTouchOutside(false);initViews();}private void initViews() {mBackgroundLayout = (BackgroundLayout) findViewById(R.id.background);mBackgroundLayout.setBaseColor(mWindowColor);mBackgroundLayout.setCornerRadius(mCornerRadius);mCustomViewContainer = (FrameLayout) findViewById(R.id.container);addViewToFrame(mView);mLabelText = (TextView) findViewById(R.id.label);setLabel(mLabel, mLabelColor);}private void addViewToFrame(View view) {if (view == null) return;int wrapParam = ViewGroup.LayoutParams.WRAP_CONTENT;ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(wrapParam, wrapParam);mCustomViewContainer.addView(view, params);}public void setView(View view) {if (view != null) {mView = view;if (isShowing()) {mCustomViewContainer.removeAllViews();addViewToFrame(view);}}}public void setLabel(String label) {mLabel = label;if (mLabelText != null) {if (label != null) {mLabelText.setText(label);mLabelText.setVisibility(View.VISIBLE);} else {mLabelText.setVisibility(View.GONE);}}}public void setLabel(String label, int color) {mLabel = label;mLabelColor = color;if (mLabelText != null) {if (label != null) {mLabelText.setText(label);mLabelText.setTextColor(color);mLabelText.setVisibility(View.VISIBLE);} else {mLabelText.setVisibility(View.GONE);}}}} }

LoadingDialog涉及到的BackgroundLayout類

package com.xiayiye.yhsh.flowerdialog;import android.annotation.TargetApi; import android.content.Context; import android.graphics.drawable.GradientDrawable; import android.os.Build; import android.util.AttributeSet; import android.widget.LinearLayout;/*** from https://github.com/Kaopiz/KProgressHUD* 增加了一個正方形顯示* update minionshuang*/ public class BackgroundLayout extends LinearLayout {private float mCornerRadius;private int mBackgroundColor;public BackgroundLayout(Context context) {super(context);init();}public BackgroundLayout(Context context, AttributeSet attrs) {super(context, attrs);init();}@TargetApi(Build.VERSION_CODES.HONEYCOMB)public BackgroundLayout(Context context, AttributeSet attrs, int defStyleAttr) {super(context, attrs, defStyleAttr);init();}@SuppressWarnings("deprecation")private void init() {int color = getContext().getResources().getColor(R.color.colorLoadingProgressBg);initBackground(color, mCornerRadius);}private void initBackground(int color, float cornerRadius) {GradientDrawable drawable = new GradientDrawable();drawable.setShape(GradientDrawable.RECTANGLE);drawable.setColor(color);drawable.setCornerRadius(cornerRadius);if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {setBackground(drawable);} else {setBackgroundDrawable(drawable);}}public void setCornerRadius(float radius) {mCornerRadius = ScaleUtils.dip2px(radius);initBackground(mBackgroundColor, mCornerRadius);}public void setBaseColor(int color) {mBackgroundColor = color;initBackground(mBackgroundColor, mCornerRadius);}//正方形顯示@Overrideprotected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {super.onMeasure(widthMeasureSpec, heightMeasureSpec);int width = getMeasuredWidth();int height = getMeasuredHeight();int size = Math.max(width, height);setMeasuredDimension(size, size);} }

BackgroundLayout里面涉及到的尺寸工具類ScaleUtils

package com.xiayiye.yhsh.flowerdialog;import android.content.res.Resources;/*** dp px sp 轉化工具**/ public class ScaleUtils {private ScaleUtils() {}public static int dip2px(float f) {return Math.round((Resources.getSystem().getDisplayMetrics().density * f) + 0.5f);}public static int px2dip(float f) {return Math.round((f / Resources.getSystem().getDisplayMetrics().density) + 0.5f);}public static int px2sp(float f) {return Math.round((f / Resources.getSystem().getDisplayMetrics().scaledDensity) + 0.5f);}public static int sp2px(float f) {return Math.round((Resources.getSystem().getDisplayMetrics().scaledDensity * f) + 0.5f);}}


看不懂得可以直接下載源碼運行即可


點擊下載源碼

總結

以上是生活随笔為你收集整理的Android开发之自定义菊花进度条对话框的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 成人午夜电影网站 | 亚洲福利影视 | 乳色吐息在线看 | 淫人网| 97人人草 | 特级丰满少妇一级aaaa爱毛片 | 3d动漫精品啪啪一区二区竹菊 | 91美女在线观看 | 午夜激情在线 | 五月婷婷av | 4438全国最大成人网 | 日批视频免费看 | 深夜免费视频 | 新97超碰 | 日韩中文字幕网站 | 蜜桃成人在线视频 | 黄色大片日本 | 日韩在线不卡av | 青青草超碰在线 | 久久久久久久久久久久久久av | 97涩涩网 | 欧亚一级片 | 亚洲av电影一区 | 日本久久不卡 | 黄色靠逼视频 | 老司机在线永久免费观看 | 亚洲乱码精品 | 欧美日韩一区二区在线视频 | 五月天中文字幕av | 色玖玖综合| 国产乱淫av公 | 97久久国产精品 | 久久综合高清 | 波多野结衣视频免费在线观看 | 免费看欧美成人a片无码 | 欧美女人一区二区 | 日韩六区| 亚洲视屏在线观看 | 国内精品国产三级国产aⅴ久 | 大胸喷奶水www视频妖精网站 | 久久久久久久久久网站 | 熟妇人妻中文av无码 | 99er在线| 精品无码三级在线观看视频 | 不卡中文| 日韩欧美一区二区三区 | 色小说香蕉 | 综合网激情| 亚洲无码久久久久久久 | 国产无遮挡又黄又爽免费视频 | 夜夜躁很很躁日日躁麻豆 | 亚洲欧美日韩一区二区三区在线观看 | 亚洲天堂久久久 | 亚洲视频精品在线观看 | 亚洲美女屁股眼交 | 午夜a视频 | av久久久久久 | 超碰在线小说 | 欧美黑人一级片 | 艳妇乳肉豪妇荡乳xxx | 探花系列在线观看 | 国产综合内射日韩久 | 亚洲美女自拍偷拍 | 玖玖综合网 | 丝袜国产视频 | 天堂最新资源在线 | 性xxxx欧美| 精品国产午夜 | 成年人网站免费看 | 在线天堂视频 | 调教亲女小嫩苞h文小说 | 伊人黄| 少妇性色av | www.av网 | 在线h片| 国产美女自拍视频 | 男人把女人捅爽 | 少妇肥臀大白屁股高清 | 美女网站免费观看 | 一二区精品 | 国产乱码一区二区三区播放 | 亚洲日本在线观看 | 亚洲精品香蕉 | 国产区在线视频 | 老女人一毛片 | 精品人妻一区二区乱码 | 特大黑人娇小亚洲女 | 公交顶臀绿裙妇女配视频 | 日本www免费| 女人被狂躁c到高潮喷水电影 | 男男肉耽高h彩漫 | 日本aⅴ视频 | 国产日韩欧美在线观看视频 | 不卡视频在线观看免费 | 中文字幕免费高清网站 | 欧美激情免费 | 国产又猛又黄 | 国产精品国产精品国产专区不卡 | 伊人久久大香线蕉av一区 |