自定义进度条颜色
Custom Progress bar color
我正在尝试将默认的绿色进度条更改为紫色。这里有些人建议创建一个包含以下代码的自定义可绘制对象 (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="#61408c"
android:endColor="#e1d2f3"
android:angle="0"
/>
</shape>
然后像这样将其设置为进度条的背景属性:
<ProgressBar
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/progressBar"
android:background="@drawable/progress"
android:layout_centerInParent="true"/>
问题是我同时看到了紫色和绿色进度条指示器。绿色在紫色的上面。不知道绿色进度条是哪里来的?效果是这样的:
我想通了。我应该在代码中设置它,而不是作为背景属性!
像这样:
mProgressBar = (ProgressBar) findViewById(R.id.progressBar);
mProgressBar.setVisibility(View.INVISIBLE);
mProgressBar.setIndeterminateDrawable(getDrawable(R.drawable.progress));
我正在尝试将默认的绿色进度条更改为紫色。这里有些人建议创建一个包含以下代码的自定义可绘制对象 (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="#61408c"
android:endColor="#e1d2f3"
android:angle="0"
/>
</shape>
然后像这样将其设置为进度条的背景属性:
<ProgressBar
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/progressBar"
android:background="@drawable/progress"
android:layout_centerInParent="true"/>
问题是我同时看到了紫色和绿色进度条指示器。绿色在紫色的上面。不知道绿色进度条是哪里来的?效果是这样的:
我想通了。我应该在代码中设置它,而不是作为背景属性! 像这样:
mProgressBar = (ProgressBar) findViewById(R.id.progressBar);
mProgressBar.setVisibility(View.INVISIBLE);
mProgressBar.setIndeterminateDrawable(getDrawable(R.drawable.progress));