Tôi đã thêm một thanh tiến trình để hoạt động của tôi bằng cách sử dụng đoạn mã sau:Làm thế nào để thay đổi màu sắc của Bar Progress trong Android - (Tôi đã thử một cách, và nó không làm việc)
<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>
Sau đó, Tôi gọi nó bằng cách:
progressbar = (LinearLayout) findViewById(R.id.linlaHeaderProgress);
progressbar.setVisibility(View.VISIBLE);
Thanh tiến trình được hiển thị và tôi muốn thay đổi màu của nó. Theo mặc định, thanh tiến trình được hiển thị bằng màu xám. Dưới đây là những gì tôi đã cố gắng để thay đổi màu sắc:
Tôi tạo ra một file xml trong thư mục drawables và đặt tên nó như activityindicator.xml
Nội dung xml này là:
<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>
Và tôi đã thay đổi các tập tin bố trí như sau:
<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>
Đây là những gì tôi đã thử, nhưng màu sắc không thay đổi. Bất cứ ai có thể cho tôi biết tôi đang làm gì sai?
Tôi đang sử dụng phiên bản Lollipop.
này cho phép linh hoạt trong việc lựa chọn colors.xml cũng progressBar.getProgressDrawable() setColorFilter (ContextCompat.getColor (getActivity(), R.color.product_status_color), PorterDuff.Mode.MULTIPLY) –
Tôi muốn bạn se Color.WHITE và dòng này không hoạt động. Tôi đã phải thay đổi chế độ porter duff sang SRC_ATOP –
Phương pháp này thay đổi màu sắc của tất cả các thanh tiến trình trong ứng dụng –