简体   繁体   English

进度对话框未在android版本8.0中显示微调器,但仍可以使用

[英]progress dialog is not showing the spinner in android version 8.0 but it still works

In my app, the progress dialog should show out when the button is clicked. 在我的应用中,单击按钮后,进度对话框应显示出来。 Now the progress dialog is shown but without spinner or the loading bar(sorry I'm not sure what it's call) 现在显示进度对话框,但没有微调框或加载栏(对不起,我不确定调用的是什么)

This is how my progress dialog looks like in android 8.0 real device 这是我的进度对话框在android 8.0真实设备中的样子

这是我的进度对话框在android 8.0真实设备中的样子

This is how my progress dialog looks like in android 5.0 这是我的进度对话框在android 5.0中的样子

在此处输入图片说明

  private ProgressDialog progressDialog;

     @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_login);
            progressDialog = new ProgressDialog(Login.this);
    }

         public void loginUser(View v) {
            final String Email = emailText.getText().toString();
            final String password = passwordText.getText().toString();

            progressDialog.setMessage("Logging in....");
            progressDialog.setCanceledOnTouchOutside(false);
            progressDialog.show();

            if (TextUtils.isEmpty(Email)) {
                emailText.setError("Email is required");
            }
            if (TextUtils.isEmpty(password)) {
                passwordText.setError("password is required");
            }
            if ((!TextUtils.isEmpty(Email)) && (!TextUtils.isEmpty(password))) {
                mAuth.signInWithEmailAndPassword(Email, password)
                        .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                            @Override
                            public void onComplete(@NonNull Task<AuthResult> task) {
                                if (!task.isSuccessful()) {
                                    Toasty.error(getApplicationContext(), "Login Failed",
                                            Toast.LENGTH_SHORT, true).show();
                                    progressDialog.dismiss();
                                } else {
      Toasty.success(getApplicationContext(), "Login Success",
                                            Toast.LENGTH_SHORT, true).show();
                                    Intent intent = new Intent(Login.this, Admins.class);
                                    intent.putExtra("Email", emailText.getText().toString());
                                    startActivity(intent);
                  }
           }
     }

Can anyone help me to solve this? 谁能帮我解决这个问题?

ProgressDialog ProgressDialog

is deprecated from SDK 26. You should use 已从SDK 26中弃用。您应该使用

ProgressBar 进度条

Usage: 用法:

In your layout add the view: 在布局中添加视图:

<ProgressBar
   android:id="@+id/progressBar"
   style="?android:attr/progressBarStyle"
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   app:layout_constraintTop_toTopOf="@+id/parent"
   app:layout_constraintBottom_toBottomOf="@+id/parent"
   app:layout_constraintLeft_toLeftOf="parent"
   app:layout_constraintRight_toRightOf="parent"
   android:layout_marginLeft="16dp"
   android:layout_marginRight="16dp"
   android:indeterminate="true"
   android:max="100"
   android:visibility="gone"/>

Declare your progressBar in your activity 在活动中声明您的progressBar

ProgressBar progressBar;

In onCreate get the view onCreate获取视图

progressBar = findViewById(R.id.progressBar);

When you need to show the progressBar: 当您需要显示progressBar时:

progressBar.setVisibility(View.VISIBLE);

When you need it to be gone: 当您需要它消失时:

progressBar.setVisibility(View.GONE);

For more details take a look into ProgressBar docs 有关更多详细信息,请查看ProgressBar文档

It could be helpful to disable user interaction while ProgressBar is up. ProgressBar启动时禁用用户交互可能会有所帮助。

EDIT 编辑

Disabling interaction 禁用互动

getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,
            WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);

Reenabling interaction: 重新启用互动:

getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);

EDIT 2 编辑2

You don't need to copy ProgressDialog visual as per Material Design patterns ( Progress Indicators ). 您不需要按照Material Design模式( Progress Indicators )复制ProgressDialog视觉对象。

EDIT 3 编辑3

Here is an example for what I said to you in comments. 这是我在评论中对您说过的例子。 It is a layout for a ProgressBar inside a View 它是View内ProgressBar的布局

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        android:layout_margin="16dp"
        android:visibility="visible"
        android:background="#EFEFEF">

        <TextView
            android:id="@+id/title"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Things to do"
            android:textSize="30sp"
            android:layout_marginLeft="10dp"
            android:layout_marginStart="10dp"/>

        <ProgressBar
            android:id="@+id/progressBar"
            style="?android:attr/progressBarStyle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="16dp"
            android:layout_marginRight="16dp"
            android:indeterminate="true"
            android:max="100"
            android:visibility="visible"
            android:layout_below="@+id/title"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Please wait we are doing things..."
            android:layout_below="@+id/title"
            android:layout_toRightOf="@+id/progressBar"
            android:layout_toEndOf="@+id/progressBar"/>
    </RelativeLayout>

</android.support.constraint.ConstraintLayout>

It'll produce something like this: 它将产生如下内容: 看起来如何

You can set elevation for API 21 or higher: 您可以为API 21或更高版本设置海拔高度:

android:elevation="10dp"

As you asked in comments, this is just an example, not a recommendation . 正如您在评论中所问的那样,这仅是示例, 而不是建议 It's not the most beautiful layout you'll see in life, but it will give you a north. 这不是您一生中会看到的最漂亮的布局,但是它将带给您北方的感觉。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM