2012-07-24 132 views
2

的颜色,我需要一个搜索栏的颜色需要这个我怎样才能改变搜索条

enter image description here

我取得了绘制一个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的背景中使用它 但是颜色不会改变:(

+1

这可以帮助你:HTTP://stackoverflow.com/questions/7056803/making-a-custom-skinny-progressbar-seekbar和http://www.mokasocial.com/2011/02/create-a-自定义风格的UI滑块 - 搜索条,在功能的Android/ – Hiral 2012-07-24 06:38:24

回答

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

0

如果你想改变你必须为progressDrawable提供一个9patch drawable的进度颜色。

你可以找到目前在Android的SDK /平台/使用的之一(-API的应用程序内,被靶向)/data/res/drawable/scrubber_primary_holo.9
(这对API 15)

香港专业教育学院发现,最简单的方法是简单的开放的形象,编辑颜色,将图像保存为一个9patch图像,并在您的应用程序/文件夹绘制。

+0

这很有趣。你用什么工具打开,编辑和保存9补丁? – faizal 2014-07-09 19:41:15

+1

设计师为我做,但我认为他使用的Photoshop。如果你不想使用全息进度,你可以看到这样的回答:http://stackoverflow.com/questions/2739186/android-how-do-i-change-the-height-of-a-progressbar/21474806 #21474806如果您使用这种方法,您可以只提供一种颜色,而不必更改9修补程序图像。 – Slickelito 2014-07-11 06:53:55