ProgressDialog 已弃用 [英] ProgressDialog is deprecated

查看:61
本文介绍了ProgressDialog 已弃用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于 ProgressDialog 已从 Android 版本 O 中弃用,我仍在寻找更好的方法来完成我的任务.任务是从我的活动转移到片段.一切正常,但进度对话框不可见.我试过实施它,但...进度对话框不起作用.

Since the ProgressDialog is deprecated from the Android version O, I'm still finding a better way out to do my task. The task is to move from my activity to the fragment. Everything is working fine but the progressdialog is not visible. I've tried implementing it but... the progressdialog doesn't work.

似乎进度条可以工作,但仍然无法工作.我需要一个进度对话框,因为我很容易设置我的标题和消息.我需要一个 Spinner progressDialog 但不知道该怎么做.这是我的一项工作,但没有实施:

It seems the progressbar would work but still not working. I need a progressdialog because it is simply easy for me to set my title and the message. I need a spinner progressDialog but don't know how to do it. Here is one of my work but not implementing :

Java 类

ublic class SaveVideo extends AppCompatActivity {

private Button button;

private ProgressDialog mProgressDialog;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_save_video);

    mProgressDialog = new ProgressDialog(this);

    getSupportActionBar().setHomeAsUpIndicator(R.drawable.back);
    getSupportActionBar().setDisplayShowTitleEnabled(false);
    getSupportActionBar().setDisplayShowHomeEnabled(true);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    button = (Button) findViewById(R.id.saveVideo);

    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            //where it must be seen when the button is pressed
            mProgressDialog.setTitle("Title");
            mProgressDialog.setMessage("Message");
            mProgressDialog.show();

            Intent intent = new Intent(SaveVideo.this,MainActivity.class);
            intent.putExtra("change",2);
            startActivity(intent);

            //as soon as the page moves from this to another fragment
            mProgressDialog.dismiss();
        }
    });


}

我是 Android O 版的新手.任何帮助都会让我学到新的东西!

I'm new to Android Version O. Any help would give me new thing to learn!

推荐答案

Android O 文档中提到:

As it is mentioned in Android O documentation:

该类在 API 级别 26 中已弃用.ProgressDialog 是一个模态对话框,它阻止用户与应用程序交互.反而使用此类时,您应该使用进度指示器,例如ProgressBar,可以嵌入到您的应用程序的 UI 中.或者,您可以使用通知来通知用户任务的进度.

This class was deprecated in API level 26. ProgressDialog is a modal dialog, which prevents the user from interacting with the app. Instead of using this class, you should use a progress indicator like ProgressBar, which can be embedded in your app's UI. Alternatively, you can use a notification to inform the user of the task's progress.

您可以使用 TextView 和 ProgressBar 创建自定义视图并管理其可见性.您可以使用 这个库,因为它使用 AlertDialog 而不是 ProgressDialog.

You can create a custom view with TextView and ProgressBar and manage its visibilty. You can use this library also because it is using AlertDialog instead of ProgressDialog.

这篇关于ProgressDialog 已弃用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆