有没有办法在SeekBar android小部件中改变黄色?

有索恩酒吗?
发布于 2011-12-22 14:46:43
步骤1:创建您的图像绘图工具(9-Patch)
在创建任何XML可绘制文件之前,请确保创建了搜索栏背景、手柄和进度部分所需的图像可绘制文件(包括一个9补丁可绘制文件)。在下面的步骤中,XML可绘制文件将使用包含9个补丁的可绘制文件。
创建以下可绘制文件,并将其放置在/res/drawable/文件夹中:
步骤2:可绘制的SeekBar进度
现在为Android搜索栏进度(示例中的蓝条部分)创建一个可绘制的XML,将其命名为seekbar_progress_bg.xml,并将其放在/res/ drawable /文件夹中:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<clip>
<shape>
<gradient
android:startColor="#FF5e8ea3"
android:centerColor="#FF32a0d2"
android:centerY="0.1"
android:endColor="#FF13729e"
android:angle="270"
/>
</shape>
</clip>
</item>
<item>
<clip>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/stripe_bg"
android:tileMode="repeat"
android:antialias="true"
android:dither="false"
android:filter="false"
android:gravity="left"
/>
</clip>
</item>
</layer-list>上面的XML首先绘制一个半透明的蓝色渐变,然后在渐变的顶部分层半透明的条纹图像。突出显示的代码行(第20行)引用在步骤1中创建的可绘制文件夹中的条纹(半透明)图像。
有关通过XML创建自定义形状的更多信息,请查看Android可绘制资源文档,特别是位图和形状部分。
步骤3:可绘制的SeekBar背景
接下来,创建主搜索栏进度可绘制项;它将为搜索栏中的搜索栏进度和secondaryProgress操作分配一个可绘制项。将您的可绘制文件命名为类似于seekbar_progress.xml的名称,将其放在/res/ drawable /文件夹中:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background">
<nine-patch
xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/seekbar_background"
android:dither="true"
/>
</item>
<item android:id="@android:id/secondaryProgress">
<clip>
<shape>
<gradient
android:startColor="#80028ac8"
android:centerColor="#80127fb1"
android:centerY="0.75"
android:endColor="#a004638f"
android:angle="270"
/>
</shape>
</clip>
</item>
<item
android:id="@android:id/progress"
android:drawable="@drawable/seekbar_progress_bg"
/>
</layer-list>上面高亮显示的代码的第一部分(第8行)引用了在步骤1中创建的搜索栏背景图像(9-patch drawable),(第29行)引用了上面在步骤2中创建的可绘制内容。
第4步:将所有内容整合在一起…
此时,您需要做的就是在声明搜索栏时将seekbar_progress命名为drawable:
<SeekBar
android:id="@+id/frequency_slider"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:max="20"
android:progress="0"
android:secondaryProgress="0"
android:progressDrawable="@drawable/seekbar_progress"
android:thumb="@drawable/seek_thumb"
/>突出显示的两行代码用于设置SeekBar项的进度和缩略图。@ drawable /seekbar_progress引用上一步中创建的XML可绘制文件。
https://stackoverflow.com/questions/8599829
复制相似问题