您的位置:首页 > 其它

自定义LoadingDialog

2016-12-23 15:29 169 查看
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();
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: