2011-11-21 83 views
1

我想在搜索栏中删除标记的颜色(在这种情况下为黄色)。Seekbar中没有标记的颜色

代码:

<SeekBar 
    android:id="@+id/seekBar1" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentLeft="true" 
    android:max="20" 
    android:progress="10" 
    android:secondaryProgress="0"/> 

是否有一个简单的方法来做到这一点?

+0

我的答案有帮助吗?任何精度? – Renaud

回答

1

请参阅View dev doc。 SeekBar派生自视图,您应该尝试在xml定义中使用具有Shape Drawable(纯色)的android:background修改背景,或者使用setBackgroundColor以编程方式更改颜色。

要删除颜色,应该尝试将其设置为纯粹的透明颜色。

我没有测试过,所以让我们知道如果失败会发生什么。

更新

你可以试试:

定义res/drawable/white_bg.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android" 
     android:shape="rectangle"> 
    <solid android:color="@android:color/white" /> 
</shape> 

将搜索栏android:background="@drawable/white_bg"

给它先用纯白色的颜色一试,看看如果这是一个好的开始...

好吧,这是行不通的。

最后更新

好了,从那里我已经定制了ProgessBar我的一个项目得到了它。由于搜索栏从进度派生,你需要定义一个res/drawable/seekbar_bg.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> 
     <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/progress"> 
    <clip> 
     <shape> 
     <corners android:radius="5dip" /> 
     <solid android:color="@android:color/transparent" /> 
     </shape> 
    </clip> 
    </item> 

</layer-list> 

同样的platforms/android-8/data/res/drawable/progress_horizontal.xml文件(机器人-8就是一个例子),并为您的搜索栏XML定义的android:progressDrawable="@drawable/seekbar_bg"属性。

我假定这样的@android:id/secondaryProgress项目不需要在Layer List被定义为一个搜索栏,但应验证...

你还可通过宣布由platforms/android-8/data/res/drawable/seek_thumb.xml激发了当地选择重新定义the thumb symbol selector

有趣的是,由于我从未使用过SeekBar,所以我学到了很多东西,谢谢! ;)

我对试用/错误的方法和多次更新的道歉...

+0

我试过sb.setBackgroundColor(Color.TRANSPARENT); - >没有任何变化 – test123123

+0

@ test123123好吧,这并不那么简单,但我编辑了我的答案,它的工作原理,我让你重新定义拇指符号,如果需要自己... – Renaud