美文网首页安卓
整合Android移动开发之:小控件、工具类

整合Android移动开发之:小控件、工具类

作者: zhongya666 | 来源:发表于2021-08-01 10:34 被阅读0次

    时间过的飞快,蓦然回首,发现自己做Android开发也好久好久好久了。没错,我是大佬我摊牌了。坐在电脑前发呆两小时后,感觉自己再不做点什么真的对不起自己的发际线,好了老铁们,那我就从现在开始吧!


    b02ac98ee8a9fbb47e13256f570219b2.jpeg

    玩库的由来

    再次强调,为了让各位大佬省点劲,我倒腾的主要目的就是要简化代码简化代码简化代码。
    关注不迷路,我会持续更新...

    项目简介

    1.基本上一个控件能用整个项目的那种,仓库地址WanLibrary
    2.WanLibrary的使用教程在我的另一个项目WanApk配合使用,其代码简单易懂,这么说吧,会写Hello World人都能看懂(附带其中一张图)。

    dc04d181f1cd4123166980a0ce5cf33.jpg
    3.欢迎浏览我的另一个项目,我用组件化的方式为该库写了一个模块,你可以单独运行该模块的代码,不过WanApk里面有更多干货哦。

    功能目录

    1.BasicDialog(一个可以复用的弹框)
    2.TimeButton(一个可以复用的倒计时按钮)
    目前比较少,我会持续整合资源...

    效果图

    dialog1.jpg
    dialog.jpg
    timebutton.gif

    依赖我,让你省时省力。

     implementation 'com.gitee.zhongya666:WanLibrary:1.0.8'
    

    使用说明(按照组件字母排序)

    BasicDialog

            var dialog = BasicDialog(requireContext())
            dialog.setContent("我真的很帅")
            dialog.show()
            dialog.setAction {
                ToastUtil.show("是的,你做出了正确的选择")
            }
    
            /**
             * 修改弹框宽度 1 - 10 (int)
             * 高度是自适应的不支持修改
             */
            var dialog = BasicDialog(requireContext(),6)
            dialog.setContent("我真的很帅")
            dialog.show()
            dialog.setActionWhich {
                if (it ==0){
                    ToastUtil.show("嗯,我知道你手误了")
                }else{
                    ToastUtil.show("是的,你做出了正确的选择")
                }
            }
    
            /**
             * 一般修改确定按钮背景色比较多,特写此方法
             */
            var dialog = BasicDialog(requireContext())
            dialog.setContent("我真的很帅")
            dialog.setAgreeBackgroundColor(ContextCompat.getColor(requireContext(),R.color.blue))
            dialog.setAgreeTextColor(ContextCompat.getColor(requireContext(),R.color.white))
            dialog.show()
    

    TimeButton

    方式一 动态设置
            /**
             * 这种方式可以不用在xml中写shape代码,更加方便
             * normalBackgroundColor 正常时的背景色
             * runBackgroundColor    执行时的背景色
             * radius 圆角大小
             */
            setEasyAttr(
                ContextCompat.getColor(context,R.color.yellow_f2),
                ContextCompat.getColor(context,R.color.color_999),
                10f
            )
    
            /**
             * 务必使用这个点击事件
             */
            setTimeButtonClickListener {
    
            }
    
    方式二 静态xml
            TimeButton 继承了TextView
            自定义以下属性
            countDownTime 倒计时时间
            textNormalColor 未点击时的字体颜色
            textRunColor 点击后的字体颜色
            textNormal 未点击时的字体
            textRun 点击后的字体
            normalBackgroundResource 未点击时的背景资源
            runBackgroundColorResource 点击后的背景资源
    
            <com.zhongya666.library.ui.TimeButton
                android:id="@+id/timeButton"
                android:layout_width="120dp"
                android:layout_height="40dp"
                android:layout_marginTop="10dp"
                android:paddingLeft="10dp"
                android:paddingTop="5dp"
                android:paddingRight="10dp"
                android:paddingBottom="5dp"
                android:textSize="15sp"
                app:countDownTime="5"
                app:textRunColor="@color/black"
                app:textNormalColor="@color/green"
                />
    

    相关文章

      网友评论

        本文标题:整合Android移动开发之:小控件、工具类

        本文链接:https://www.haomeiwen.com/subject/jgvlvltx.html