2013-03-25 45 views
6

我试图创建一个薄,蓝色进度条,与此类似:细细的蓝色进度条

enter image description here

我不是Drawables那么好,但我有什么改变ProgressBar到绿色,但我不知道如何使它薄和蓝色:

<?xml version="1.0" encoding="UTF-8"?> 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:orientation="vertical" 
    > 
     <ProgressBar 
     android:id="@+id/ProgressBar" 
     android:layout_centerInParent="true" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:progressDrawable="@drawable/progress" 
     style="@android:style/Widget.ProgressBar.Horizontal" 
     android:visibility="gone" 
    /> 

</LinearLayout> 

可绘制

<?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="5dip" /> 
      <gradient 
        android:startColor="#ff9d9e9d" 
        android:centerColor="#ff5a5d5a" 
        android:centerY="0.75" 
        android:endColor="#ff747674" 
        android:angle="270" 
      /> 
     </shape> 
    </item> 

    <item android:id="@android:id/secondaryProgress"> 
     <clip> 
      <shape> 
       <corners android:radius="5dip" /> 
       <gradient 
         android:startColor="#80ffd300" 
         android:centerColor="#80ffb600" 
         android:centerY="0.75" 
         android:endColor="#a0ffcb00" 
         android:angle="270" 
       /> 
      </shape> 
     </clip> 
    </item> 
    <item 
     android:id="@android:id/progress" 
    > 
     <clip> 
      <shape> 
       <corners 
        android:radius="5dip" /> 
       <gradient 
        android:startColor="#33FF33" 
        android:endColor="#008000" 
        android:angle="270" /> 
      </shape> 
     </clip> 
    </item> 

</layer-list> 
+0

机器人:layout_height = “xxdp” – TacB0sS 2013-03-25 23:37:42

+0

Possbile重复使用: http://stackoverflow.com/questions/3950956/changing-progress -bar-color-using-xml-in-android-app?rq = 1 – 2013-03-26 00:33:58

+0

发布你的结果... – TacB0sS 2013-03-26 19:08:09

回答

6

高度由android:layout_height="wrap_content属性定义。例如,您可以将其设置为2dp,以创建更细的进度栏。

由于您使用的是渐变,所以更改颜色会有点困难。所以你必须改变你的开始&结束颜色某种蓝色。

我在用

<ProgressBar 
    android:id="@+id/progressbar" 
    style="?android:attr/progressBarStyleHorizontal" 
    android:layout_width="match_parent" 
    android:layout_height="4dp" 
    android:layout_marginTop="0.01dp" 
    android:max="100" 
    android:progress="50" 
    android:progressDrawable="@drawable/myprogressbar" 
    android:secondaryProgress="0" /> 

MyProgressBar.xml在绘制文件夹

<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:id="@android:id/background"> 
     <shape> 
      <corners android:radius="0dip" /> 
      <gradient android:startColor="#C0C0C0" android:centerColor="#F8F8FF" 
       android:centerY="0.75" android:endColor="#ffffff" android:angle="90" /> 
      <stroke android:width="0.01dp" android:color="#6B8E23" /> 
     </shape> 
    </item> 
    <item android:id="@android:id/progress"> 
     <clip> 
      <shape> 
       <corners android:radius="0dip" /> 
       <gradient android:startColor="#9ACD32" android:endColor="#FFFF00" 
        android:angle="90" /> 
       <stroke android:width="1dp" android:color="#6B8E23" /> 
      </shape> 
     </clip> 
    </item> 
</layer-list> 

用自己的蓝色代码更换彩色代码:

android:startColor =“#C0C0C0”android :centerColor = “#F8F8FF” 机器人:ENDCOLOR = “#FFFFFF”