android - 请求网络的时候出现自定义的对话框
大家讲道理
大家讲道理 2017-04-17 17:57:17
[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();
    }
大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

全部回复(2)
PHPz

不要在子线程中调用UI

activity.runOnUiThread(new Runnable() {
    @Override
    public void run() {
        dialog.show();
    }
});

这样试试

巴扎黑

有个重写的方法 onProgressUpdate,把对话框写在里面

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号