300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > 设置progressbar进度条颜色

设置progressbar进度条颜色

时间:2024-05-19 16:34:27

相关推荐

设置progressbar进度条颜色

1、在drawable目录下新建XML文件progressbar_horizontal_red:

[java]view plaincopy<?xmlversion="1.0"encoding="utf-8"?> <!-- Copyright(C)TheAndroidOpenSourceProjectLicensedunderthe ApacheLicense,Version2.0(the"License");youmaynotusethisfile exceptincompliancewiththeLicense.Youmayobtainacopyofthe Licenseat/licenses/LICENSE-2.0Unlessrequired byapplicablelaworagreedtoinwriting,softwaredistributedunder theLicenseisdistributedonan"ASIS"BASIS,WITHOUTWARRANTIESOR CONDITIONSOFANYKIND,eitherexpressorimplied.SeetheLicensefor thespecificlanguagegoverningpermissionsandlimitationsunderthe License. --> <layer-listxmlns:android="/apk/res/android"> <itemandroid:id="@android:id/background"> <shape> <cornersandroid:radius="5dip"/> <gradientandroid:startColor="#ff333333" android:centerColor="#ff4a4a4a"android:centerY="0.75" android:endColor="#ff333333"android:angle="270"/> </shape> </item> <itemandroid:id="@android:id/secondaryProgress"> <clip> <shape> <cornersandroid:radius="5dip"/> <gradientandroid:startColor="#8000AADD" android:centerColor="#8000AADD"android:centerY="0.75" android:endColor="#8000AADD"android:angle="270"/> </shape> </clip> </item> <itemandroid:id="@android:id/progress"> <clip> <shape> <cornersandroid:radius="5dip"/> <gradientandroid:startColor="#fffa6b6b" android:centerColor="#ffff0000"android:centerY="0.75" android:endColor="#ffe80202"android:angle="270"/> </shape> </clip> </item> </layer-list>

2、在values目录下新建XML文件styles:

[java]view plaincopy<?xmlversion="1.0"encoding="utf-8"?> <resources> <stylename="progressbarStyle_Horizontal_Red"parent="android:Widget.ProgressBar.Horizontal"> <itemname="android:indeterminateOnly">false</item> <itemname="android:progressDrawable">@drawable/progressbar_horizontal_red</item> <itemname="android:minHeight">12.0dp</item> <itemname="android:maxHeight">12.0dp</item> </style> </resources>

3、布局文件代码:

[java]view plaincopy<ProgressBar android:layout_width="fill_parent" android:layout_height="wrap_content" style="@style/progressbarStyle_Horizontal_Red"/>

运行起来之后可以发现水平进度条已经变成红色的了~

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。