我使用以下代码向我的活动添加了进度条:
<LinearLayout
android:id="@+id/linlaHeaderProgress"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="vertical"
android:visibility="gone" >
<ProgressBar
android:id="@+id/pbHeaderProgress"
android:indeterminateOnly="true"
android:keepScreenOn="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</ProgressBar>
</LinearLayout>
然后我通过以下方式调用它:
progressbar = (LinearLayout) findViewById(R.id.linlaHeaderProgress);
progressbar.setVisibility(View.VISIBLE);
显示进度条,我想更改其颜色。默认情况下,进度条显示为灰色。这是我尝试更改颜色的方法:
我在drawables文件夹中创建了一个xml文件,并将其命名activityindicator.xml
为该xml的内容是:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="@android:id/secondaryProgress">
<color android:color="#f58233" />
</item>
<item android:id="@android:id/progress">
<color android:color="#f58233" />
</item>
</layer-list>
我将布局文件更改为:
<LinearLayout
android:id="@+id/linlaHeaderProgress"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:progressDrawable="@drawable/activityindicator"
android:orientation="vertical"
android:visibility="gone" >
<ProgressBar
android:id="@+id/pbHeaderProgress"
android:indeterminateOnly="true"
android:keepScreenOn="true"
android:progressDrawable="@drawable/activityindicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</ProgressBar>
</LinearLayout>
这是我尝试过的方法,但是颜色没有改变。谁能告诉我我在做什么错?
我正在使用棒棒糖版本。
如果只想更改颜色,请在进度栏中添加滤色器:
pbHeaderProgress.getIndeterminateDrawable().setColorFilter(Color.RED, Mode.MULTIPLY);
Mode参数是指PorterDuff.Mode值-在此处可用。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句