Skip to content

JadynAi/Kotlin-D

Repository files navigation

Kotlin-D

D! 这是一个会长期,但不定期维护的辅助工具项目。因为UP主也就是本人,脑袋常常会短路。
Kotlin-D是一个帮助开发者,提高生产效率的项目,主要面向Android移动端的项目。

配置远程库

项目的build.gradle配置JCenter远程仓库。在需要的地方引用:

api 'com.jadynai.ai.kotlind:KotlinD:1.1.2'

如何使用

使用准备

使用前,请将你的项目中的Application继承com.jadyn.ai.kotlind.base.BaseApplication

open class BaseApplication : Application() {
    
    companion object {
        lateinit var instance: Application
    }

    override fun onCreate() {
        super.onCreate()
        instance = this
    }
}

BaseApplication 已经废弃,使用Application的方式对项目侵入性太强。自Version 1.0.7之后使用如下方式初始化:

KD.init(application对象)

在启动时init,这是一个非常简单的类,只对外提供了一个Application对象。在类似于getDrawable或者getColor这类方法会用到。

#### Recyclerview AcrobatAdapter是为Recyclerview提供的适配器,使用DSL模式构建。可以灵活配置多Item样式,仅用两三行代码为为Item添加单击、长按、双击事件使用文档

1.0.6版本开始将适配器从库里移除,确保工具库为一个单纯的工具库存在

函数说明文档

View相关

不需要为各种View添加Drawable,而去写一些烦扰的Drawable.xml或者Selector.xml文件,只需在代码中一键配置,轻松快捷。

  • 为View添加Press效果:
// 资源
View.press(@DrawableRes normalRes: Int, @DrawableRes pressRes: Int)

// 直接设置drawable
View.press(normal: Drawable, press: Drawable)

// 颜色
View.pressColor(normalColor: Int, pressColor: Int)
  • 为View添加Enable效果
// 设置资源
fun View.enabled(@DrawableRes normalRes: Int, @DrawableRes pressRes: Int)

// 设置drawable
fun View.enabled(normal: Drawable, press: Drawable, drawableHandle: (StateListDrawable) -> Unit = {})

………………其余函数同press相关函数
  • 相应地还有checke、selected相关状态设置,使用函数跟press相同

  • checkBox之类的设置button drawable

// 设置资源ID
checkedButton(@DrawableRes normalRes: Int, @DrawableRes pressRes: Int)

// 设置颜色
CompoundButton.checkedColorButton(normalColor: Int, checkedColor: Int)
  • 设置圆角等背景

字符串扩展

  • 字符串末端添加Drawable。TextvView的drawableEnd只能居于末端,控制位置只能增加padding或者设置drawablePadding。
String.drawableEnd(@DrawableRes id: Int, padding: Float = 0f, size: android.util.Size? = null): CharSequence

LICENSE

Copyright [JadynAi]

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

About

Kotlin-D,使用Kotlin封装的各种便于开发的辅助工具,提高生产效率

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published