try 了许多解决方案,但对此问题都不起作用
Problem:个 我在我的Android应用程序中有一个进度条,我对它应用了一个自定义样式,使其成为水平的,并改变其背景和进度 colored颜色 .但是,当我将浅色设置为父布局的背景时,进度条的背景 colored颜色 变为灰色,而不是我在样式中指定的原始 colored颜色 .
当我将深色设置为父布局的背景时
Color used:个个
<color name="colorYellow">#E2DA85</color>
个
当我将牛奶或任何浅阴影 colored颜色 设置为父布局的背景时
Color used:个个
<color name="colorMilk">#FDFDF5</color>
个
这是我的activity layout%文件:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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:BACKGROUND="@COLOR/COLOR黄色"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<ProgressBar
android:id="@+id/progressBook"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="20dp"
android:layout_marginTop="100dp"
android:progress="75"
style="@style/CustomProgressBar"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
请注意
Android:BACKGROUND="@COLOR/COLOR黄色"
下面是名为CustomProgressBar的进度条的自定义样式:
<style name="CustomProgressBar" parent="android:Widget.ProgressBar.Horizontal">
<item name="android:indeterminateOnly">false</item>
<item name="android:progressDrawable">@drawable/progressbar_book</item>
<item name="android:minHeight">10dip</item>
<item name="android:maxHeight">20dip</item>
</style>
下面是我为进度栏创建的名为progressbar_book的自定义可绘制文件:
<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background">
<shape>
<corners android:radius="10dp" />
<gradient
android:startColor="@color/colorCotton"
android:centerColor="@color/colorCotton"
android:centerY="0.50"
android:endColor="@color/colorCotton"
android:angle="270" />
</shape>
</item>
<item android:id="@android:id/progress">
<clip>
<shape>
<corners android:radius="10dp" />
<gradient
android:startColor="@color/colorViolet"
android:endColor="@color/colorViolet"
android:angle="90" />
</shape>
</clip>
</item>
</layer-list>
colorCotton:个
<color name="colorCotton">#F2F6EE</color>
个
How can I get the progressbar to show the correct background color even when the parent layout has a light color background?个