加垂直的彩色线搜索栏背景绘制
问题描述:
如何动态地单独垂直彩色线条添加到搜索条的进度条?加垂直的彩色线搜索栏背景绘制
我已经有progress.xml,progress_fill.xml和个人可绘制创建background_fill文件,让我定制我的搜索条在一定程度上。但是,根据具体情况,可能需要以各种不同的颜色绘制各条垂直线条,并且可能需要在搜索栏上的任意点绘制垂直线条。它们不能在XML布局文件中设置。
我想我需要通过编程写一点颜色rects到background_fill.xml绘制(我progress_fill已被设置为几乎透明)。
我该怎么做编程写那些豆蔻rects我background_fill.xml绘制?
我做的一个TextView类似的东西,在我使用的SpannableStringBuilder和ImageSpan的小rects写入到一个TextView。但我没有看到它可用于seekbar小部件。
答
通过扩展搜索栏小工具这篇。两个步骤:首先,创建一个名为CustomSeekBar新类来扩展搜索栏:
package com.example.seekbar;
class CustomSeekBar extends SeekBar {
public CustomSeekBar(Context context) {
super(context);
}
public CustomSeekBar(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CustomSeekBar(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
private Paint paintRect = new Paint();
paintRect.setColor(Color.rgb(142, 196, 0));
private Rect audioRect = new Rect();
audioRect.set(5, 7, 4, 18);
canvas.drawRect(audioRect, paintRect);
}
}
其次,参照本CustomSeekBar在布局XML文件:如果使用im这个技术,然后
<view class="com.example.seekbar.CustomSeekBar"
android:id="@+id/seekBar0"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp" />
我怎么会从可绘制文件夹应用自定义的拇指? – Erum 2014-08-07 17:09:19