首页 > 解决方案 > 工具栏中的进度条未在android中显示

问题描述

我有以下xml

<androidx.appcompat.widget.Toolbar
                android:layout_width="match_parent"
                android:layout_height="50dp"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                android:background="@color/colorPrimary"
                android:id="@+id/toolbar">

            <ProgressBar
                    android:id="@+id/toolbarprogress"
                    android:layout_width="25dp"
                    android:shadowColor="@color/red"
                    android:rotation="@integer/google_play_services_version"
                    android:layout_height="25dp" />

        </androidx.appcompat.widget.Toolbar>

在我的活动中,我有这两种方法

protected fun showProgress() {

        toolbarprogress?.let {
            it.visibility = View.VISIBLE
        }
    }

    protected fun hideProgress() {

        toolbarprogress?.let {
            it.visibility = View.GONE
        }
    }

当我调用 showProgress 方法时它没有显示在我的工具栏中的问题,任何人都可以建议这里缺少什么吗?

标签: androidkotlinprogress-barandroid-toolbar

解决方案


我使用了相同的代码,并且它与我的工作正常。setSupportActionBar(toolbar)如果您的工具栏不可见,请确保使用。


推荐阅读