如何更改搜索栏的颜色

时间:2012-07-24 06:27:37

标签: android seekbar

我需要一个颜色需要这个

的搜索栏

enter image description here

我在drawable中制作了一个xml文件,其渐变设置在

之下
 <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

 <item android:id="@android:id/background">
     <shape>
        <corners android:radius="5dip" />

        <gradient
            android:angle="270"
            android:centerColor="#808080"
            android:centerY="0.75"
            android:endColor="#808080"
            android:startColor="#808080" />
    </shape>
</item>
<item android:id="@android:id/secondaryProgress">
    <clip>
        <shape>
            <corners android:radius="2dip" />

            <gradient
                android:angle="270"
                android:centerColor="#09488D"
                android:centerY="0.75"
                android:endColor="#09488D"
                android:startColor="#09488D" />
        </shape>
    </clip>
</item>
<item android:id="@android:id/progress">
    <clip>
        <shape>
            <corners android:radius="5dip" />

            <gradient
                android:angle="270"
                android:centerColor="#09488D"
                android:centerY="0.75"
                android:endColor="#09488D"
                android:startColor="#09488D" />
        </shape>
    </clip>
 </item>

</layer-list>

然后这个xml在seekbar的背景中使用它 但颜色没有变化:(

2 个答案:

答案 0 :(得分:4)

在搜索栏中包含此内容:

            <SeekBar 
                android:progressDrawable="@drawable/progress"
                android:thumb="@drawable/thumb"/>

其中progress.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" 
    android:drawable="@drawable/background_fill" />

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

和thumb.xml:

<?xml version="1.0" encoding="utf-8"?>    
<selector xmlns:android="http://schemas.android.com/apk/res/android">
   <item android:drawable="@drawable/thumb_fill" />
</selector>

您也可以参考此链接 - http://www.mokasocial.com/2011/02/create-a-custom-styled-ui-slider-seekbar-in-android/http://www.anddev.org/seekbar_progressbar_customizing-t6083.html

答案 1 :(得分:0)

如果您想更改进度的颜色,您必须为progressDrawable提供9patch drawable。

您可以在android-sdk / platforms /(-api-your-app-is-targeting)/data/res/drawable/scrubber_primary_holo.9中找到当前正在使用的那个。 (那是api 15)

我发现最简单的方法是简单地打开图像,编辑颜色,将图像保存为9patch图像并放入应用程序/可绘制文件夹。