转载请注明出处:https://blog.csdn.net/weixin_43277878/article/details/91379795
话不多说先上图,一个类解决问题
支持xml自定义属性为:
font_size | 底部文字字体大小 |
font_color | 底部文字颜色 |
space | 底部文字与seekbar之间的间距 |
seekbar_height | seekbar的高度 |
seekbar_background_select | seekbar选择范围的背景色 |
seekbar_background | seekbar默认背景色 |
point_size | 选择器圆点的直径 |
point_color | 选择器圆点的颜色 |
其他可通过代码设置的属性为:
setDefaultTabIndex(int start_index, int end_index);//默认开始/结束位置的下标
setTabNames(String[] names);//设置底部文字数组
setSelectListener(ShinnRangeSeekBarListener listener);//设置监听器
getTabNames();//返回底部文字数组
update();//更新当前控件状态
如何在自己的项目中使用:
在xml中直接使用:
<你放置的路径.ShinnRangeSeekBar
android:id="@+id/seekbar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
需要使用自定义属性记得,在xml文件顶部加上一句xmlns:app="http://schemas.android.com/apk/res-auto",
然后就可以通过如app:font_size去使用自定义属性了
在java代码中使用
mRangeseekbar.setSelectListener(new ShinnRangeSeekBar.ShinnRangeSeekBarListener() {
@Override
public void selectLeftTab(String name, int index) {
}
@Override
public void selectRightTab(String name, int index) {
}
});
attrs.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="ShinnRangeSeekBar">
<attr name="font_size" format="dimension" />
<attr name="font_color" format="color" />
<attr name="space" format="dimension" />
<attr name="seekbar_height" format="dimension" />
<attr name="seekbar_background_select" format="color" />
<attr name="seekbar_background" format="color" />
<attr name="point_size" format="dimension" />
<attr name="point_color" format="color" />
</declare-styleable>
</resources>
代码已上传csdn
https://download.csdn.net/download/weixin_43277878/11237094
如果你有其他需求和不明白的地方的话,可以留言给我,我们一起努力进步~!
问题补充:
当控件与scrollview嵌套使用时,会出现和父控件滑动事件冲突的问题,请添加以下代码,到控件类中即可
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
getParent().requestDisallowInterceptTouchEvent(true);
return super.dispatchTouchEvent(ev);
}