android:progressDrawable的作用

效果图:

这里写图片描述

上为:SeekBar

下为:ProgressBar

布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <SeekBar
        android:id="@+id/sb"
        android:layout_width="match_parent"
        android:layout_height="30dp"
        android:progressDrawable="@drawable/layer_list_seekbar" />

    <ProgressBar
        android:id="@+id/pb"
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="match_parent"
        android:layout_height="30dp"
        android:progressDrawable="@drawable/layer_list_progressbar" />
</LinearLayout>

注意:

 android:progressDrawable="@drawable/layer_list_progressbar" 

该属性: 设置进度中的背景颜色和进度颜色

layer_list_seekbar

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@android:id/background">
        <shape>
            <corners android:radius="3dp" />
            <gradient
            android:angle="270"
            android:centerColor="#2B2B2B"
            android:centerY="0.75"
            android:endColor="#ff747674"
            android:startColor="#ff9d9e9d" />
            <solid android:color="#2B2B2B" />
        </shape>
    </item>

    <item android:id="@android:id/progress">
        <clip>
            <shape>
                <corners android:radius="3dp" />
                <gradient
                    android:angle="270"
                    android:centerColor="#ff3399CC"
                    android:centerY="0.75"
                    android:endColor="#ff6699CC"
                    android:startColor="#ff0099CC" />
                <solid android:color="#2496F6" />
            </shape>
        </clip>
    </item>
</layer-list>

layer_list_progressbar

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:id="@android:id/background">
        <shape>
            <corners android:radius="2dp" />
            <gradient
                android:angle="270"
                android:centerColor="@color/colorPrimaryDark"
                android:endColor="#ff4801"
                android:startColor="#f5f5f5" />
        </shape>
    </item>
    <item android:id="@android:id/progress">
        <clip>
            <shape>
                <corners android:radius="2dp" />
                <gradient
                    android:centerColor="#ff7612"
                    android:endColor="#ff7612"
                    android:startColor="#ff7612" />
            </shape>
        </clip>
    </item>

</layer-list>

注意:

  <item android:id="@android:id/background">
设置背景

 <item android:id="@android:id/progress">
设置进度

MainActivity

public class MainActivity extends AppCompatActivity {

    private ProgressBar mPb;
    private SeekBar mSb;

    @RequiresApi(api = Build.VERSION_CODES.N)
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mPb = ((ProgressBar) this.findViewById(R.id.pb));
        mSb = ((SeekBar) this.findViewById(R.id.sb));

        mSb.setProgress(50);
        mPb.setProgress(50, true);

    }


}
  • 4
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值