Kotlin
-
[Kotlin] 비밀번호 정규식Android 2021. 8. 9. 20:31
숫자, 문자, 특수문자 중 2가지 포함(6~15자) ^(?=.*[a-zA-Z0-9])(?=.*[a-zA-Z!@#$%^&*])(?=.*[0-9!@#$%^&*]).{6,15}$ fun isPasswordFormat(password: String): Boolean { return password.matches("^(?=.*[a-zA-Z0-9])(?=.*[a-zA-Z!@#\$%^&*])(?=.*[0-9!@#\$%^&*]).{6,15}\$".toRegex()) }
-
[Kotlin] isNullOrBlank vs isNullOrEmptyAndroid 2021. 7. 23. 16:05
// 널을 가질 수 있는 스트링 var testString: String? = null Log.e("",testString.isNullOrBlank()?.toString()) // true Log.e("",testString.isNullOrEmpty()?.toString()) // true // 길이가 0인 스트링 var testString: String = "" Log.e("",testString.isNullOrBlank()?.toString()) // true Log.e("",testString.isNullOrEmpty()?.toString()) // true // 길이가 1 이상인 스트링 var testString: String = "NotEmptyAndNotBlank" Log.e("",testSt..
-
deprecated startActivityForResultAndroid 2021. 5. 28. 12:06
fun openActivityForResult() { startForResult.launch(Intent(this, AnotherActivity::class.java)) } val startForResult = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result: ActivityResult -> if (result.resultCode == Activity.RESULT_OK) { val intent = result.data // Handle the Intent //do stuff here } } in Kotlin
-
[Android] StatusBar height 상태바 높이 구하기Android 2021. 3. 10. 15:50
/** * 상단 상태바 높이 계산 후 DP로 반환 * @param context Context * @return Int(DP값) */ fun getStatusBarHeightDP(context: Context): Int { var result = 0 val resourceId: Int = context.resources.getIdentifier("status_bar_height", "dimen", "android") if (resourceId > 0) { result = context.resources.getDimension(resourceId).toInt() } return result }
-
The 'kotlin-android-extensions' Gradle plugin is deprecated.Android 2021. 2. 15. 16:53
1. Kotlin synthetic Update View Bindings or Data Bindings in App level gradle file and then use binding instance 2. Parcelable Remove plugin kotlin-android-extension & add plugin kotlin-parcelize in App level gradle file In kotlin version 1.4.20
-
[Kotlin] HashMapAndroid 2020. 12. 16. 00:43
fun main(args: Array){ val hashMap:HashMap = HashMap() //define empty hashmap hashMap.put(1,"Ajay") hashMap.put(3,"Vijay") hashMap.put(4,"Praveen") hashMap.put(2,"Ajay") println(".....traversing hashmap.......") for(key in hashMap.keys){ println("Element at key $key = ${hashMap[key]}") } } Output: .....traversing hashmap....... Element at key 1 = Ajay Element at key 2 = Ajay Element at key 3 = V..