代码之家  ›  专栏  ›  技术社区  ›  Kevin F

Xamarin:进度条更改颜色

  •  3
  • Kevin F  · 技术社区  · 10 年前

    我有一个ProgressBar xml:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <ProgressBar
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/progressBar"
            style="@android:style/Widget.ProgressBar.Large" />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="25sp"
            android:text="Loading..." />
    </LinearLayout>
    

    我需要更改默认颜色(灰色)。我需要用程序或xml格式更改颜色。

    在我的活动中,我有:

    SetContentView(Resource.Layout.LoadingBar);
    var progressBar = FindViewById<ProgressBar>(Resource.Id.progressBar);
    
    2 回复  |  直到 10 年前
        1
  •  3
  •   GTInsight    10 年前

    我想这就是你要找的。我的示例是,如果秒的值低于10,那么进度条的颜色将变为红色。

    if (seconds < 10) {
    progressBar.ProgressDrawable.
    SetColorFilter (Android.Graphics.Color.Red, Android.Graphics.PorterDuff.Mode.Multiply);}
    
        2
  •  1
  •   CodeSi    7 年前

    此代码更改为预期的颜色和屏幕中心

    <ProgressBar
        android:id="@+id/loading_progress"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:visibility="invisible"
        android:indeterminate="true"
        android:indeterminateTintMode="src_atop"
        android:indeterminateTint="@color/colorprimary"
        android:progressDrawable="@drawable/login_loading" />