Android(安卓)自定义View双向选择带气泡SeekBar
16lz
2021-01-26
android自定义View seekbar
双向选择;
支持气泡功能,气泡文字,背景样式可以自定义;
进度条按钮,颜色,宽度在xml中设置;
「GitHub地址」用的上的话,点star不迷路,小老弟跪求了~
样式
使用
Grade
allprojects {repositories {...maven { url 'https://www.jitpack.io' }}} dependencies { implementation 'com.github.yujinzhao123:DoubleHeadedDragonBar:1.0.4'}
Maven
jitpack.io https://www.jitpack.io com.github.yujinzhao123 DoubleHeadedDragonBar 1.0.4
属性
<?xml version="1.0" encoding="utf-8"?><resources> <declare-styleable name="DoubleHeadedDragonBar"> <attr name="button_width" format="dimension" /> <attr name="button_height" format="dimension" /> <attr name="button_img" format="reference"/> <attr name="text_color" format="color"/> <attr name="bg_color" format="color"/> <attr name="value_color" format="color"/> <attr name="seek_height" format="dimension"/> declare-styleable>resources>
案layout
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#fff" tools:context=".MainActivity"> <cn.bar.DoubleHeadedDragonBar android:layout_margin="10dp" android:id="@+id/bar" app:text_color="#5C6980" app:button_img="@drawable/button" android:layout_width="match_parent" android:layout_height="wrap_content" /> <cn.bar.DoubleHeadedDragonBar android:layout_below="@+id/bar" android:layout_margin="10dp" android:id="@+id/bar1" app:text_color="#1B97F7" app:button_img="@mipmap/seek_button" app:button_height="40dp" app:button_width="40dp" app:bg_color="#999" app:value_color="#e97051" app:seek_height="6dp" android:layout_width="match_parent" android:layout_height="wrap_content" />RelativeLayout>
Activity
final int maxValue = 6; bar = findViewById(R.id.bar); //设置单位刻度显示 bar.setUnit("0公斤", "6公斤"); bar.setCallBack(new DoubleHeadedDragonBar.DhdBarCallBack() { //返回气泡显示文字 @Override public String getMinMaxString(int value, int value1) { return value + "~" + value1; }//结束触摸 按百分比返回选择值,范围 0~100 @Override public void onEndTouch(float minPercentage, float maxPercentage) { } }); //设置气泡按钮 testView2 = (TextView) LayoutInflater.from(this).inflate(R.layout.toast_view, null); bar.setToastView2(testView2); testView = (TextView) LayoutInflater.from(this).inflate(R.layout.toast_view, null); bar.setToastView(testView); testView.setText("0"); testView1 = (TextView) LayoutInflater.from(this).inflate(R.layout.toast_view, null); bar.setToastView1(testView1); testView1.setText("6"); bar1 = findViewById(R.id.bar1); bar1.setUnit("0", "100"); bar1.setMinValue(10); bar1.setMaxValue(80); }
更多相关文章
- android 状态栏颜色
- android中按键的扫描码和键值
- ActivityGroup使用问题
- android分享功能的实现
- Buttons in button bars should be borderless;
- Android(安卓)SpannableStringBuilder可以实现一个TextView多种
- Android(安卓)ImageButton Example 图片按钮
- 使用SpannableString设置部分文字大小、颜色、超链接、点击事件
- android 键盘 send按钮