Android -- SeekBar(I)颜色,颜色设置

Android – SeekBar(I)颜色,颜色设置

Android -- SeekBar(I)颜色,颜色设置_第1张图片


<SeekBar
     android:id="@+id/bar_r"
     android:layout_width="255dp"
     android:layout_height="wrap_content"/>


<SeekBar
    android:id="@+id/bar_g"
    android:layout_width="255dp"
    android:layout_height="wrap_content"
    android:progressTint="@color/colorGreen"
    android:thumbTint="@color/colorGreen" />


<SeekBar
    android:id="@+id/bar_b"
    android:layout_width="255dp"
    android:layout_height="wrap_content"
    android:maxHeight="2dp"
    android:thumb="@drawable/ic_thumb_bike"
    android:progressDrawable="@drawable/ic_seekbar_stytle" />

布局内设置:


android:progressDrawable="@drawable/seekbar_style"

android:progressTint="@android:color/red"

android:progressBackgroundTint="@android:color/white"


android:thumb="@drawable/ic_thumb_bicycle"

android:thumbTint="@color/red"

PS: 当同时使用自定义的滑块样式和进度条样式时,若需保持进度条为线状(否则高度将于滑块高度一致),可增加以下属性:

android:maxHeight="2dp" 

seekbar_style.xml(seekbar含三层叠加效果)

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@android:id/background"> 
        <shape>
            <corners android:radius="1dp"/>
            <solid android:color="@color/colorTY_Little"/>
        shape>
    item>

    <item android:id="@android:id/secondaryProgress"> 
        <clip> 
            <shape>
                <corners android:radius="1dp"/>
                <solid android:color="@color/colorTY_Half" />
            shape>
        clip>
    item>

    <item android:id="@android:id/progress"> 
        <clip>
            <shape>
                <corners android:radius="1dp"/>
                
                <gradient
                    android:angle="0"
                    android:startColor="#4facfe"
                    android:endColor="#00f2fe"/>
            shape>
        clip>
    item>
layer-list>

ic_thumb_bike.xml (由 Vector Asset 生成)

<vector android:height="24dp" android:tint="#66CCFF"
    android:viewportHeight="24" android:viewportWidth="24"
    android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
    <path android:fillColor="#ffffff" android:pathData="M20,11c-0.18,0 -0.36,0.03 -0.53,0.05L17.41,9H20V6l-3.72,1.86L13.41,5H9v2h3.59l2,2H11l-4,2L5,9H0v2h4c-2.21,0 -4,1.79 -4,4c0,2.21 1.79,4 4,4c2.21,0 4,-1.79 4,-4l2,2h3l3.49,-6.1l1.01,1.01C16.59,12.64 16,13.75 16,15c0,2.21 1.79,4 4,4c2.21,0 4,-1.79 4,-4C24,12.79 22.21,11 20,11zM4,17c-1.1,0 -2,-0.9 -2,-2c0,-1.1 0.9,-2 2,-2c1.1,0 2,0.9 2,2C6,16.1 5.1,17 4,17zM20,17c-1.1,0 -2,-0.9 -2,-2c0,-1.1 0.9,-2 2,-2s2,0.9 2,2C22,16.1 21.1,17 20,17z"/>
vector>

Java代码控制:

seekBar.getThumb().setColorFilter(Color.RED, PorterDuff.Mode.SRC_ATOP);//滑块
seekBar.getProgressDrawable().setColorFilter(Color.RED, PorterDuff.Mode.SRC_ATOP);//进度条

参考:Android SeekBar 样式设置

你可能感兴趣的:(Android,控件,android)