Click me to jump to GitHub
JCenter
android
implementation 'com. Ayvytr: KTX: 3.0.0'
Copy the code
androidx
implementation 'com. Ayvytr: KTX - androidx: 3.0.0'
Copy the code
ChangeLog
3.0.0
- Added the view.onclick extension to prevent repeated clicks or respond to multiple click events
- TextChange extension method, afterTextChange after an interval of time to execute the action, can set whether to trigger the action when text is empty, especially useful in delayed search scenarios. Equivalent to textView.textChanges () in RxBinding
- Increased ActivityStack finishExceptTop ()
- Increase the Context getConnectivityManager, network to determine whether a network connection
- Other code optimization, comment modification
2.5.4
- Modify InputMethodManager to get the instance from the Application Context
- – Added Fragment and Activity setActivityTitle() to fix invalid calls to activity.setTitle () (e.g., when using Navigation)
2.5.3
Change the function of converting dp, sp, px from Context to.dp,.sp,.dp2px, sp2px, px2dp, px2sp
2.5.1
Add ActivityStack to enable you to open and close specific activities, close all activities, close all activities except specified activities, and terminate processes.
2.5.0
Added the Spanner utility class to provide easy to use SpannableString operations for TextView
2.4.3
Simplified tool classes add methods such as Fragment getStringArray
Against 2.4.1
- BaseTextWatcher
- ChineseFilter
- EmailFilter
- EmojiFilter
- PasswordFilter
Contains content and usage
View new method
[^ # ^ # ^ #] [^ # ^ # ^ #]?? You can modify the value of doActionAfterTimes in response to multi-hit events
view.onClick(doActionAfterTimes=1, millisecondInterval=500) {/ / click action
}
// Text change listener: Delay action by timeout milliseconds, default timeout=300ms, default ignoreEmpty=true, empty string does not trigger action
editText.textChange(timeout=300, ignoreEmpty = true) {/ / search action
}
Copy the code
network.kt
getConnectivityManager
isNetworkConnected
isWifiConnected
isMobileDataConnected
Copy the code
Dp. Kt Float, Int dp, sp related extension method
Int.dp
Int.sp
Float.dp
Float.sp
Int.dp2px
Float.dp2px
Int.sp2px
Float.sp2px
Int.px2dp
Float.px2dp
Int.px2sp
Float.px2sp
Copy the code
ActivityStack
registerCallback()
unregisterCallback()
getRunningActivityCount()
isForeground()
getCurrentActivity()
finish()
finishCurrent()
finishAll()
finishAllExcept()
start()
startAndFinishOthers()
finishExceptTop()
forceClose()
Copy the code
Spanner SpannableString Manipulation tool class
bold
italic
normal
boldItalic
font
strikethrough
underline
backgroundColor
backgroundColorRes
textColorRes
textColor
pressedBackgroundColor
pressedBackgroundRes
onClick
onLongClick
Copy the code
Clipboard.kt Common methods of Clipboard operations
val clipboardManager = getClipboardManager()
clibboardManager.getText2()
clibboardManager.setText2()
clibboardManager.getUri()
clibboardManager.setUri()
clibboardManager.getIntent()
clibboardManager.setIntent()
Copy the code
Context.kt has minimal code to handle the loading layout, and various convenience methods are provided
Context.getStatusBarHeight() Context.inflate(...) //RecyclerView subitem load method context.inflaterv (...)Copy the code
Managers. Kt Android common management class a method directly obtain, without type conversion cumbersome
context.getAccountManager()
context.getInputMethodManager()
context.getConnectivityManager
...
Copy the code
Res.kt Obtains android string, drawable and other resources
Context.getstringarray () // Methods with the number 2 at the end of the name are distinguished from methods deprecated or versioned in the native SDK context.getDrawableArray() context.getDrawableIdArray() ...Copy the code
Screen.kt get Screen size, judge vertical Screen, switch vertical Screen and other methods
context.getDisplayMetrics()
context.isLandscape()
context.setLandscape()
context.getScreenWidth()
context.getScreenHeight()
Copy the code
The simplest toast.kt Toast uses the extended method of sharing a Toast instance internally
context.toast(...)
context.toastLong(...)
Copy the code
Activity.kt Activity extension method
activity.showActionBar
activity.hideActionBar
activity.getContext
activity.fullscreen(boolean)
...
Copy the code
Bitmap.kt provides a method to convert Bitmap and Drawable into each other
View. Kt View extension method
view.show()
view.hide()
view.invisible()
view.isShow()
Copy the code
// Set EditText text and move the cursor to the end of the text editText.settext2 (…)
/ / set the EditText text, and text selection EditText. SetTextWithSelection (...).Copy the code