android - Seekbar中没有标记颜色

标签 android

我想删除搜索栏中标记的颜色(在本例中为黄色)。

代码:

<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"/>

有没有简单的方法可以做到这一点?

最佳答案

参见 View dev doc . SeekBar 派生自 View,您应该尝试在 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>

设置SeekBar android:background="@drawable/white_bg"

首先尝试使用纯白色,看看这是否是一个好的开始......

好吧,那行不通。

最后更新

好的,从我定制了 ProgessBar 的项目中得到的。由于 SeekBar 派生自 ProgressBar,因此您需要定义一个 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_horizo​​ntal.xml文件(以android-8为例)并定义android:progressDrawable="@drawable/seekbar_bg" SeekBar xml 定义的属性。

我假设 @android:id/secondaryProgress 项目不需要在 Layer List 中定义对于 SeekBar 但它应该被验证......

你也可以重新定义 the thumb symbol selector通过声明受 platforms/android-8/data/res/drawable/seek_thumb.xml 启发的本地选择器。

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

我对试错法和多次更新表示歉意......

关于android - Seekbar中没有标记颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8216820/

相关文章:

android - 渲染期间引发异常 : Numbers of source Raster bands and source color space components do not match

java - 在 Serialized 接口(interface)下重写 readObject() 和 writeObject() 方法如何在实际开发中找到应用?

android - 如何获取所有号码的联系人?我做错了什么?

android - 如果 adb logcat 上的条件不起作用

android - 来自一个 Activity 的asyncTask在另一个 Activity android中运行

Android 负边距不起作用

Android V7 支持库弹出菜单

android - 编辑两侧带有图标的文本

php - 如何知道命名空间、url、soap action 和方法名是什么?

java - android 正则表达式提取数据时出现问题 - 日志上的 PID