android - 请求网络的时候出现自定义的对话框
本文介绍了android - 请求网络的时候出现自定义的对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
public static Dialog createLoadingDialog(Context context){
LayoutInflater inflater = LayoutInflater.from(context);
View v = inflater.inflate(R.layout.loading_dialog, null);// 得到加载view
LinearLayout layout = (LinearLayout) v.findViewById(R.id.dialog_view);// 加载布局
// main.xml中的ImageView
ImageView spaceshipImage = (ImageView) v.findViewById(R.id.imgLoading);
SceneAnimation s = new SceneAnimation(spaceshipImage,imglist,1);
// Glide.with(context).load(R.drawable.et_loader).asGif().diskCacheStrategy(DiskCacheStrategy.SOURCE).into(spaceshipImage);
Dialog loadingDialog = new Dialog(context,R.style.loadingDialogStyle);// 创建自定义样式dialog
loadingDialog.setCancelable(true);// 不可以用返回键取消
loadingDialog.setContentView(layout, new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.FILL_PARENT,
LinearLayout.LayoutParams.FILL_PARENT));// 设置布局
return loadingDialog;
}
这是我对话框的代码;
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
dialog.dismiss();
}
@Override
protected void onPreExecute() {
super.onPreExecute();
dialog = LoadingDialog.createLoadingDialog(activity);
dialog.show();
}
解决方案
不要在子线程中调用UI
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
dialog.show();
}
});
这样试试
这篇关于android - 请求网络的时候出现自定义的对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文