进度对话框没有在Android版本8.0中显示微调器,但它仍然有效

问题描述 投票:0回答:1

在我的应用程序中,进度对话框应显示单击按钮的时间。现在显示进度对话框,但没有微调器或加载栏(抱歉,我不确定它的调用是什么)

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

This is how my progress dialog looks like in android 8.0 real device

这是我的进度对话框在android 5.0中的样子

enter image description here

  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);
                  }
           }
     }

任何人都可以帮我解决这个问题吗?

android progressdialog
1个回答
4
投票

ProgressDialog

从SDK 26弃用。您应该使用

进度条

用法:

在您的布局中添加视图:

<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"/>

在你的活动中声明你的progressBar

ProgressBar progressBar;

onCreate得到了看法

progressBar = findViewById(R.id.progressBar);

当您需要显示progressBar时:

progressBar.setVisibility(View.VISIBLE);

当你需要它消失时:

progressBar.setVisibility(View.GONE);

有关更多详细信息,请查看ProgressBar文档

ProgressBar启动时禁用用户交互可能会有所帮助。

编辑

禁用交互

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

重新启用互动:

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

编辑2

您不需要根据Material Design模式(ProgressDialog)复制Progress Indicators visual。

编辑3

这是我在评论中对你说的一个例子。它是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>

它会产生这样的东西:How it looks

您可以为API 21或更高版本设置高程:

android:elevation="10dp"

正如您在评论中提到的,这只是一个例子,而不是推荐。这不是你在生活中看到的最美丽的布局,但它会给你一个北方。

© www.soinside.com 2019 - 2024. All rights reserved.