我想设计一个看起来像下图的寻求栏。
在此输入图片描述]1 。
通过使用默认的寻找栏,我将得到这样的东西。
所以我需要的是只改变颜色。我不需要额外的样式。有什么直接的方法可以做到这一点,或者我应该建立我的自定义可画性。
我试着建立自定义的,但我不能得到如上所示的精确的。 在使用定制的drawable后,我得到的是如下所示。
在此输入图片描述]3 !
如果我需要建立一个自定义的,那么请建议如何减少进度线的宽度和形状。
我的自定义实现。
background_fill.xml。
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<gradient
android:angle="90"
android:centerColor="#FF555555"
android:endColor="#FF555555"
android:startColor="#FF555555" />
<corners android:radius="1dp" />
<stroke
android:width="1dp"
android:color="#50999999" />
<stroke
android:width="1dp"
android:color="#70555555" />
</shape>
progress_fill.xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<gradient
android:angle="90"
android:centerColor="#FFB80000"
android:endColor="#FFFF4400"
android:startColor="#FF470000" />
<corners android:radius="1dp" />
<stroke
android:width="1dp"
android:color="#50999999" />
<stroke
android:width="1dp"
android:color="#70555555" />
</shape>
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>
拇指.xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval" >
<gradient
android:angle="270"
android:endColor="#E5492A"
android:startColor="#E5492A" />
<size
android:height="20dp"
android:width="20dp" />
</shape>
seekbar:
<SeekBar
android:id="@+id/seekBarDistance"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="88dp"
android:progressDrawable="@drawable/progress"
android:thumb="@drawable/thumb" >
</SeekBar>
我将从Android源代码中提取drawables和xml,并将其颜色改为红色。 下面是我如何完成mdpi绘图的例子。
自定义red_scrubber_control.xml
(添加到res/drawable)。
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/red_scrubber_control_disabled_holo" android:state_enabled="false"/>
<item android:drawable="@drawable/red_scrubber_control_pressed_holo" android:state_pressed="true"/>
<item android:drawable="@drawable/red_scrubber_control_focused_holo" android:state_selected="true"/>
<item android:drawable="@drawable/red_scrubber_control_normal_holo"/>
</selector>
自定义:red_scrubber_progress.xml
。
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@android:id/background"
android:drawable="@drawable/red_scrubber_track_holo_light"/>
<item android:id="@android:id/secondaryProgress">
<scale
android:drawable="@drawable/red_scrubber_secondary_holo"
android:scaleWidth="100%" />
</item>
<item android:id="@android:id/progress">
<scale
android:drawable="@drawable/red_scrubber_primary_holo"
android:scaleWidth="100%" />
</item>
</layer-list>
然后从Android源代码中复制所需的可画性,我从这个链接中取了1。
最好为每个hdpi、mdpi、xhdpi复制这些drawables。例如,我只使用mdpi。
然后用Photoshop把颜色从蓝色改为红色。
red_scrubber_control_disabled_holo.png。 。
red_scrubber_control_focused_holo.png: 。
Red_scrubber_control_normal_holo.png: 。
red_scrubber_control_pressed_holo.png: 。
Red_scrubber_primary_holo.9.png: 红色橡胶的主要功能。
Red_scrubber_secondary_holo.9.png: 。
Red_scrubber_track_holo_light.9.png: 。
在布局中添加SeekBar。
<SeekBar
android:id="@+id/seekBar1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:progressDrawable="@drawable/red_scrubber_progress"
android:thumb="@drawable/red_scrubber_control" />
结果。
如果你想要一模一样的条形图,但却是红色的,你可以通过编程添加一个PorterDuff颜色过滤器。你可以通过ProgressBar基类的方法来获得你想要着色的每一个可画性。然后为它设置一个颜色过滤器。
mySeekBar.getProgressDrawable().setColorFilter(new PorterDuffColorFilter(srcColor, PorterDuff.Mode.MULTIPLY));
如果想要的颜色调整不能通过波特-达夫滤镜进行,您可以指定自己的颜色滤镜。