自定义搜索栏不显示背景颜色

时间:2013-05-23 05:23:49

标签: android

我正在使用以下搜索栏

<SeekBar
    android:id="@+id/sbCardSpeed"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:layout_marginRight="5dp"
    android:max="100"
    android:progress="50"
    android:progressDrawable="@drawable/seekbar_progress"/>

seekbar_progress.xml:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@android:id/background"
        android:drawable="@drawable/background_fill"
    />

    <item
        android:id="@android:id/progress"
        android:drawable="@drawable/seekbar_progress_bg"
    />
</layer-list>

background_fill.xml:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <gradient 
        android:startColor="#FFFFFF" //white color
        android:centerColor="#FFFFFF"
        android:endColor="#FFFFFF"
        android:angle="90" />

</shape>

seekbar_progress_bg.xml:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <gradient 
        android:startColor="#FF8400"  //orange color
        android:centerColor="#FF8400"
        android:endColor="#FF8400"
        android:angle="90" />

</shape>

进度条是一种颜色的问题,即橙色。如果我移动拇指,两侧仍然是橙色。白色背景没有显示。我做错了什么?

谢谢 enter image description here

1 个答案:

答案 0 :(得分:2)

试试这个......

seekbar_progress.xml:

<?xml version="1.0" encoding="utf-8"?>
<level-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:maxLevel="10000" android:drawable="@drawable/progress_horizontal_orange" />
</level-list>

<强> progress_horizo​​ntal_orange.xml

<?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>
           <gradient
                android:startColor="#ffffff"
                android:endColor="#ffffff"/>
    </shape>
</item>

<item android:id="@android:id/progress">
    <clip>
        <shape>
            <gradient
                 android:startColor="#FF8400"
                 android:endColor="#FF8400"
                 android:angle="90"
            />
        </shape>
    </clip>
</item>

</layer-list>