1 Star 2 Fork 0

Zerlings / SmartDialog

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

SmartDialog

SmartDialog是一款简单灵活的弹窗生成框架,用于快速创建弹窗,相比原生Dialog能减少大量代码。

支持DataBinding。

Requirement

Kotlin / Java(需开启kotlin插件支持)

Android API 19+

1.0.0以上版本仅支持AndroidX

Usage

1.快速使用

//Kotlin
SmartDialog.Builder(this)
    .setLayoutResId(R.layout.dialog_test)
    .setFullScreen(true)
    .setGravity(Gravity.CENTER)
    .bind { dialog, view ->
        view.tv_test.text = "test";
    }
    .refresh { dialog, view ->
        i++
        view.tv_test.text = "${view.tv_test.text}+$i"
    }.build().show()
        
//Kotlin with DataBinding
SmartDialog.Builder<DialogTestBinding>(this)
    .setLayoutResId(R.layout.dialog_test)
    .setFullScreen(true)
    .setGravity(Gravity.CENTER)
    .bind { dialog, binding ->
        binding.tvTest.text = "test"
    }
    .refresh { dialog, binding ->
        i++
        binding.setVariable(BR.test, "${binding.tvTest.text}+$i")
    }.build().show()
            
//Java
SmartDialog testDialog = new SmartDialog.Builder(this)
    .setLayoutResId(R.layout.dialog_test)
    .setFullScreen(true)
    .setGravity(Gravity.CENTER)
    .bind(new Function2<SmartDialog, View, Unit>() {
        @Override
        public Unit invoke(SmartDialog smartDialog, View view) {
            //todo
            return null;
        }
    })
    .refresh(new Function2<SmartDialog, View, Unit>() {
        @Override
        public Unit invoke(SmartDialog smartDialog, View view) {
            //todo
            return null;
        }
    }).build();
testDialog.show();

//Java with DataBinding
SmartDialog<DialogTestBinding> testDialog = new SmartDialog.Builder<DialogTestBinding>(this)
    .setLayoutResId(R.layout.dialog_test)
    .setFullScreen(true)
    .setGravity(Gravity.CENTER)
    .bind(new Function2<SmartDialog<DialogTestBinding>, DialogTestBinding, Unit>() {
        @Override
        public Unit invoke(SmartDialog<DialogTestBinding> dialog, DialogTestBinding binding) {
            //todo
            return null;
        }
    })
    .refresh(new Function2<SmartDialog<DialogTestBinding>, DialogTestBinding, Unit>() {
        @Override
        public Unit invoke(SmartDialog<DialogTestBinding> dialog, DialogTestBinding binding) {
            //todo
            return null;
        }
    })
    .build();
testDialog.show();
  • Note: 和DataBinding一起使用时需要声明泛型为layout对应的绑定类

3.API

name info
setLayoutResId(layoutResId: Int) 设置布局文件
setAnimStyle(animStyle: Int) 设置动画样式
setCancelable(cancelable: Boolean) 是否能取消
setGravity(gravity: Int) 弹窗位置
setFullScreen(fullScreen: Boolean) 是否全屏
setBackGroundTransparent(backGroundTransparent: Boolean) 背景是否透明
bind(block: (dialog: SmartDialog, view: View) -> Unit) 用于界面初始化和绑定监听器,只在dialog创建时执行一次
refresh(block: (dialog: SmartDialog, view: View) -> Unit) 用于刷新界面,dialog每次show()时都会执行

Include

首先在项目根目录下的build.gradle中加入(已有则忽略):

allprojects {
    repositories {
        ...
        maven { url "https://jitpack.io" }
    }
}

然后在app文件夹下的build.gradle中引入:

dependencies {
    implementation 'com.gitee.Zerlings:SmartDialog:1.0.1'
}

License

MIT License

Copyright (c) 2020 Zerlings

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial    Copyright (c) 2020 Zerlings

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
MIT License Copyright (c) 2020 Zerlings Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

SmartDialog是一款简单灵活的弹窗生成框架,用于快速创建弹窗,相比原生Dialog能减少大量代码。支持DataBinding。 展开 收起
Android
MIT
取消

发行版 (5)

全部

贡献者

全部

近期动态

加载更多
不能加载更多了
Android
1
https://gitee.com/Zerlings/SmartDialog.git
git@gitee.com:Zerlings/SmartDialog.git
Zerlings
SmartDialog
SmartDialog
master

搜索帮助