自定义LoadingDialog

public class LoadingDialog extends Dialog {

   public LoadingDialog(Context context) {
      super(context);
      setLoadingDialog(context);
   }
   
   public LoadingDialog(Context context, int theme) {
      super(context, theme);
      setLoadingDialog(context);
   }
   
   private void setLoadingDialog(Context context){
      //不可取消
//    this.setCancelable(false);
      LinearLayout linearLayout = new LinearLayout(context);
      linearLayout.setOrientation(LinearLayout.VERTICAL);
      linearLayout.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
      ProgressBar progressBar = new ProgressBar(context, null,android.R.attr.progressBarStyle);
      TextView textView = new TextView(context);
      LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
      params.setMargins(0, 45, 0, 0);
      textView.setLayoutParams(params);
      textView.setTextColor(context.getResources().getColor(R.color.white));
      textView.setTextSize(16);
      textView.setText("正在加载...");
      linearLayout.addView(progressBar);
      linearLayout.addView(textView);
      this.addContentView(linearLayout, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
   }

}

//style文件

<style name="LoadingDialog" parent="android:Theme.Dialog">
    <item name="android:windowNoTitle">true</item>
    <item name="android:background">#00000000</item>
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:colorBackgroundCacheHint">@null</item>
    <item name="android:windowIsTranslucent">true</item>
</style>
//

LoadingDialog dialog = new LoadingDialog(getActivity(), R.style.LoadingDialog);
dialog.show();
//dialog.cancel();


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值