经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » 移动开发 » Android » 查看文章
Android DSelectorBryant 单选滚动选择器
来源:cnblogs  作者:YangBryant  时间:2019/10/12 9:04:41  对本文有异议

单选滚动选择器、diy丰富、有阻尼效果、简单美观、触摸or点击模式 (Rolling Selector, Diy Rich, Damping Effect, Simple and Beautiful, Touch or Click Mode)

Github地址

YangsBryant/DSelectorBryant 

(Github排版比较好,建议进入这里查看详情,如果觉得好,点个star吧!)


 

引入module

  1. allprojects {
  2. repositories {
  3. google()
  4. jcenter()
  5. maven { url 'https://www.jitpack.io' }
  6. }
  7. }

 

  1. implementation 'com.github.YangsBryant:DSelectorBryant:1.0.2'


主要代码

  1. public class MainActivity extends AppCompatActivity {
  2. DSelectorPopup dSelectorPopup;
  3. ConstraintLayout constraintLayout;
  4. ArrayList<String> list = new ArrayList<>();
  5. Button button;
  6. @Override
  7. protected void onCreate(Bundle savedInstanceState) {
  8. super.onCreate(savedInstanceState);
  9. setContentView(R.layout.activity_main);
  10. for (int i = 0; i <= 10; i++) {
  11. list.add("YMF"+i);
  12. }
  13. dSelectorPopup = new DSelectorPopup(this,list);
  14. dSelectorPopup.build();
  15. constraintLayout = findViewById(R.id.main);
  16. button = findViewById(R.id.button);
  17. button.setOnClickListener(new View.OnClickListener() {
  18. @Override
  19. public void onClick(View v) {
  20. //弹出窗体
  21. dSelectorPopup.popOutShadow(constraintLayout);
  22. }
  23. });
  24. /*点击监听器
  25. Tips:实现此监听器,点击button也会返回当前选中项的下标和文本,因此button既可以当做取消用,也可以当做确定用*/
  26. dSelectorPopup.setSelectorListener(new DSelectorPopup.SelectorClickListener() {
  27. @Override
  28. public void onSelectorClick(int position, String text) {
  29. Toast.makeText(MainActivity.this,text,Toast.LENGTH_SHORT).show();
  30. //缩回窗体
  31. dSelectorPopup.dismissPopup();
  32. }
  33. });
  34. //滑动监听器
  35. /*dSelectorPopup.setSelectoMoverListener(new DSelectorPopup.SelectorMoveListener() {
  36. @Override
  37. public void onSelectorMove(int position, String text) {
  38. Toast.makeText(MainActivity.this,text,Toast.LENGTH_SHORT).show();
  39. }
  40. });*/
  41. }
  42. }

 

参数实例

  1. dSelectorPopup.setOffset(5)
  2. .setTextSize(30)
  3. .setTextcolor_selection(getResources().getColor(R.color.colorAccent))
  4. .setTextcolor_unchecked(getResources().getColor(R.color.colorPrimary))
  5. .setGradual_color(0xffD81B60)
  6. .setTitleText("我是标题")
  7. .setTitleColor(getResources().getColor(R.color.colorPrimary))
  8. .setTitleSize(25)
  9. .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) 滑动监听器

原文链接:http://www.cnblogs.com/94xiyang/p/11653340.html

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号