如何在Android中自定义进度栏我正在开发一个应用程序,我想在其中显示一个ProgressBar,但我想替换默认的android。ProgressBar.那么如何自定义ProgressBar?我需要一些图形和动画吗?我读了下面的文章,但没能让它起作用:自定义进度栏Android
1 回答
神不在的星期二
TA贡献1963条经验 获得超6个赞
ProgressBar
customprogressbar.xml
res->drawable
自定义Progressbar.xml
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <!-- Define the background properties like color etc --> <item android:id="@android:id/background"> <shape> <gradient android:startColor="#000001" android:centerColor="#0b131e" android:centerY="1.0" android:endColor="#0d1522" android:angle="270" /> </shape> </item> <!-- Define the progress properties like start color, end color etc --> <item android:id="@android:id/progress"> <clip> <shape> <gradient android:startColor="#007A00" android:centerColor="#007A00" android:centerY="1.0" android:endColor="#06101d" android:angle="270" /> </shape> </clip> </item></layer-list>
progressDrawable
customprogressbar.xml
<ProgressBar android:id="@+id/progressBar1" style="?android:attr/progressBarStyleHorizontal" android:progressDrawable="@drawable/custom_progressbar" android:layout_width="wrap_content" android:layout_height="wrap_content" />
在运行时执行以下操作
// Get the Drawable custom_progressbar Drawable draw=res.getDrawable(R.drawable.custom_progressbar);// set the drawable as progress drawable progressBar.setProgressDrawable(draw);
添加回答
举报
0/150
提交
取消