如何自定义一个进度条在Android中 [英] How to Customize a Progress Bar In Android
问题描述
我工作的一个应用程序中,我要表现出进度
,但我想,以取代默认的Android 进度
。
I am working on an app in which I want to show a ProgressBar
, but I want to replace the default Android ProgressBar
.
所以,我怎么可以自定义进度
?
So how can I customize the ProgressBar
?
我需要一些图形和动画是什么?
Do I need some graphics and animation for that?
我阅读下面的职位,但不能让他们的工作:
I read the following posts but could not get them to work:
<一个href="http://stackoverflow.com/questions/15377805/how-to-customize-progress-barspinner-in-android">How定制android的进度条(微调)
推荐答案
我所描述的这种带有code和在这个博客的一个例子: <一个href="http://www.learnandroideasily.blogspot.in/2013/05/custom-progress-bar-in-android.html">Customized进度条的Android
自定义进度
需要定义属性或属性的进度栏的背景和进展情况。
Customizing a ProgressBar
requires defining the attribute or properties for the background and progress of your progress bar.
创建名为customprogressbar.xml在你的水库 - >绘制文件夹的XML文件:
Create an XML file named customprogressbar.xml in your res->drawable folder:
custom_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设置(绘制)
Now you need to set the progressDrawable
property in customprogressbar.xml (drawable)
您可以在XML文件或活动做到这一点(在运行时)。
You can do this in the XML file or in the Activity (at run time).
执行以下步骤,您的XML:
Do the following in your 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);
编辑:修正XML布局
corrected xml layout
这篇关于如何自定义一个进度条在Android中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!