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();
自定义LoadingDialog
最新推荐文章于 2024-05-28 22:02:45 发布