我正在尝试复制这个Dialog。
但我只是到了这一点(仅显示相关部分):
一种在我的自定义Seekbar“进度区域”周围添加细黑色边框的方法,以及仅限于“进度区域”的平铺背景。
实际上,我的CustomSeekBar
(extends AppCompatSeekBar
)可以在代码中设置起始和结束颜色。这是功能:
public void setGradientColor(@ColorInt int leftColor, @ColorInt int rightcolor) {
grad = new GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT,
new int[] {leftColor, rightcolor});
setProgressDrawable(grad);
}
但是尝试设置背景的图像最终看起来就像我在The current state
图像中的最后一个搜索栏(背景延伸到进度区域之外并填充所有视图的区域):
aSeekBar.setBackground(context.getDrawable(R.drawable.checker));
aSeekBar.setGradientColor(Color.parseColor("#00000000"), Color.parseColor("#FF000000"));
我在checker.xml
的res/drawable
文件:
<?xml version="1.0" encoding="utf-8"?>
<bitmap
xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/checkerstile"
android:tileMode="repeat"
/>
对于问题的“边框”部分,您只需向GradientDrawable添加一个笔画:
public void setGradientColor(@ColorInt int leftColor, @ColorInt int rightcolor) {
grad = new GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT,
new int[] {leftColor, rightcolor});
grad.setStroke(/* stroke width*/, /* int color*/);
setProgressDrawable(grad);
}
为此,它很容易,抱歉我无法帮助的背景。
我找到了一个可行的解决方案:
int padding = aSeekBar.getPaddingStart();
InsetDrawable bgImg = new InsetDrawable(context.getDrawable(R.drawable.checker), padding);
aSeekBar.setBackground(bgImg);
将此与the solution from Olivier结合用于边界,您将得到以下结果: