Android DSelectorBryant 单选滚动选择器
程序员文章站
2023-10-27 09:19:16
单选滚动选择器、diy丰富、有阻尼效果、简单美观、触摸or点击模式 (Rolling Selector, Diy Rich, Damping Effect, Simple and Beautiful, Touch or Click Mode) Github地址 YangsBryant/DSelect ......
单选滚动选择器、diy丰富、有阻尼效果、简单美观、触摸or点击模式 (rolling selector, diy rich, damping effect, simple and beautiful, touch or click mode)
github地址
(github排版比较好,建议进入这里查看详情,如果觉得好,点个star吧!)
引入module
allprojects { repositories { google() jcenter() maven { url 'https://www.jitpack.io' } } }
implementation 'com.github.yangsbryant:dselectorbryant:1.0.2'
主要代码
public class mainactivity extends appcompatactivity { dselectorpopup dselectorpopup; constraintlayout constraintlayout; arraylist<string> list = new arraylist<>(); button button; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); for (int i = 0; i <= 10; i++) { list.add("ymf"+i); } dselectorpopup = new dselectorpopup(this,list); dselectorpopup.build(); constraintlayout = findviewbyid(r.id.main); button = findviewbyid(r.id.button); button.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { //弹出窗体 dselectorpopup.popoutshadow(constraintlayout); } }); /*点击监听器 tips:实现此监听器,点击button也会返回当前选中项的下标和文本,因此button既可以当做取消用,也可以当做确定用*/ dselectorpopup.setselectorlistener(new dselectorpopup.selectorclicklistener() { @override public void onselectorclick(int position, string text) { toast.maketext(mainactivity.this,text,toast.length_short).show(); //缩回窗体 dselectorpopup.dismisspopup(); } }); //滑动监听器 /*dselectorpopup.setselectomoverlistener(new dselectorpopup.selectormovelistener() { @override public void onselectormove(int position, string text) { toast.maketext(mainactivity.this,text,toast.length_short).show(); } });*/ } }
参数实例
dselectorpopup.setoffset(5) .settextsize(30) .settextcolor_selection(getresources().getcolor(r.color.coloraccent)) .settextcolor_unchecked(getresources().getcolor(r.color.colorprimary)) .setgradual_color(0xffd81b60) .settitletext("我是标题") .settitlecolor(getresources().getcolor(r.color.colorprimary)) .settitlesize(25) .setbutton_background(getresources().getdrawable(r.drawable.popup_bg)).build();
tips:分割线的颜色值为:0xff 加上16进制颜色值,例如:0xffd81b60
dselectorbryant属性大全
方法名 | 属性 |
build() | 参数设置完毕,在最后build一下 |
setheights(int height) | popupwindow的高度,单位dp |
isoutside(boolean bl) | 点击弹窗外是否消失,默认true |
setseletion(int offset) | 对话框中当前项上面和下面的项数 |
setoffset(int seletion) | 默认选中项 |
settextsize(int size) | 文本字体大小 |
settextcolor_selection(int textcolor_selection) | 选中文本颜色 |
settextcolor_unchecked(int textcolor_unchecked) | 未选中文本颜色 |
setgradual_color(int gradual_color) | 分割线颜色 |
setfining(boolean fining) | 是否开启分割线两端变细,默认true |
settitletext(string titletext) | 标题的文字 |
settitlesize(int titlesize) | 标题文字大小 |
settitlecolor(int titlecolor) | 标题文字颜色 |
setbuttontext(string buttontext) | 按钮文本 |
setbuttonsize(int buttonsize) | 按钮文字大小 |
setbuttoncolor(int buttoncolor) | 按钮文字颜色 |
setbutton_background(drawable drawable) | 按钮背景 |
setbuttonwidt(int buttonwidt) | 按钮宽度,单位dp |
setbuttonheight(int buttonheight) | 按钮高度,单位dp |
popoutshadow(view view) | 显示弹窗 |
dismisspopup() | 关闭弹窗 |
setselectorlistener(selectorclicklistener selectorlistener) | 点击监听器 |
setselectomoverlistener(selectormovelistener selectomoverlistener) | 滑动监听器 |