簡體   English   中英

如何使進度條的背景變白?

[英]How to make background of progressbar white?

我正在創建一個 Android 應用程序,當屏幕上有一些 UI 時,我必須在其中顯示進度條。 但是當進度條正在顯示時,我希望進度條的背景是白色的,而不是透明的。

我想要這樣的圖像:

應用程序中的進度條圖片

我試過這段代碼:

public void showProgressDialogPraneeth(String message, boolean cancelable, boolean cancelOnTouchOutside) {
        if (progressDialog == null) {
            progressDialog = new ProgressDialog(this, R.style.PraneethProgressDialog);
        }
        progressDialog.setCancelable(cancelable);
        progressDialog.setCanceledOnTouchOutside(cancelOnTouchOutside);
        progressDialog.setMessage(message);

        if (!progressDialog.isShowing()) {
            progressDialog.show();
        }
}

PraneethProgressDialog樣式為:

<style name="PraneethProgressDialog" parent="Theme.AppCompat.Light.Dialog.Alert">
    <item name="android:background">@color/white</item>
    <item name="colorAccent">@color/spinner_progess_bar_color</item>
    <item name="android:windowBackground">@color/white</item>
</style>

無論我嘗試什么,背景要么是透明的,要么進度條會到頂部。 我經歷了很多答案,花了很多時間。 請幫我解決一下這個。

在drawable文件夾中創建progress.xml根據需要更改漸變顏色

<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
      android:pivotX="50%" 
      android:pivotY="50%" 
      android:fromDegrees="0"
      android:toDegrees="360">

    <shape 
        android:shape="ring" 
        android:innerRadiusRatio="3"
        android:thicknessRatio="8" 
        android:useLevel="false">

    <size 
        android:width="76dip" 
        android:height="76dip" />

    <gradient 
        android:type="sweep" 
        android:useLevel="false"
        android:startColor="#447a29" 
        android:endColor="#00ffffff"
        android:angle="0"/>

    </shape>

</rotate> 

而你的進度條碼看起來像這樣

<ProgressBar
  android:id="@+id/ProgressBar01" 
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:indeterminateDrawable="@drawable/progress"
 />

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM