Android快速开发库 使用Kotlin开发安卓必备

739 阅读1分钟
原文链接: github.com

Kotlin-Extract is a "toolbox" for Kotlin Android developer. like anko , The library contains a lot of helpers for Android SDK, including, but not limited to:

depend

Step 1. Add the JitPack repository to your build file Add it in your root build.gradle at the end of repositories:

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

Step 2. Add the dependency

	dependencies {
	        compile 'com.github.jiang111:Kotlin-Extract:lasted_version'
	}

Feature

  • toast
_toast("hello")
_long_toast("hello")
  • dp,sp,px
_dip2px(20)
_sp2px(20)
...
  • SharedPreference

config in your application

SharedPreferenceImpl.init(this, "name")

then

sp_saveString("key","value")
sp_getString("key")
...
  • async
val t = _async {
    Thread.sleep(3000)
    _runUI {
      hello.text = "hello"
    }
}
t.cancel()
  • startActivity/Sercice
_startActivity<Activity>("id" to 5, "name" to "hello", "age" to 12, "male" to true)
_startService<Service>("id" to 5, "name" to "hello", "age" to 12, "male" to true)
...
  • loadColor/Drawable
_loadColor(R.color.f)
_loadDrawable(R.drawable.f)
...
  • log
//in Application
LogImpl.init(debug,tag)
// use in any class
_i(msg="msg",tag="tag")
_i(msg="msg")
_json(msg="msg",tag="tag")
_json(msg="msg")
...