kotlin

2020年GitHub 上那些优秀Android开源库,这里是Top10!

只谈情不闲聊 提交于 2020-08-06 02:55:01
前言 每过一段时间呀,我都会给大家带来一些从Github上收集的一些开源库,有的是炫酷动效,有的则是实用的工具和类库。以前没看过或者没有收藏的同学,建议先收藏,以下是链接: 【Android珍藏】推荐10个炫酷的开源库 【开源推荐】进阶实战,从一款音乐播放器开始 2020年有哪些优秀的开源库呢?本期就为大家带精选的10个,排名不分先后。 No1. LiquidSwipe 这是一个很棒的ViewPager库,它在浏览ViewPager的不同页面时,显示波浪的滑动动画,效果非常炫酷。该库的USP是触摸交互的。这意味着在视图中显示类似液体的显示过渡时,应考虑触摸事件。 1.1如何使用呢? 导入以下Gradle依赖项: implementation 'com.github.Chrisvin:LiquidSwipe:1.3' 然后将 LiquidSwipeLayout 添加为保存fragment布局的容器的根布局: <androidx.constraintlayout.widget.ConstraintLayout xmlns:android = "http://schemas.android.com/apk/res/android " android:layout_width = "match_parent " android:layout_height = "match_parent "

Android 11 开发者常见问题 | FAQ・第一期

孤街浪徒 提交于 2020-08-05 13:55:05
存储 01 Q: Android 11 的分区存储是强制的吗?如果 targetSdkVersion 低于 Android 10,运行在 Android 11 的手机上,分区存储特性还生效吗? 当应用的 targetSdkVersion 升级到 Android 11 时,分区存储特性会强制生效。但如果应用 targetSdkVersion 未升级到 Android 11,运行在 Android 11 系统上时,分区存储不会强制生效。但根据 Google Play 的政策,在每一个 Android 大版本发布之后的次年 8 月,所有新发布的应用 targetSdkVersion 都需要升级至该版本或更高版本,且在版本发布的次年 11 月,所有应用 targetSdkVersion 都需要升级至该版本或更高版本。 02 Q: 清理工具类应用如何帮助用户清理应用专属目录中的数据? MANAGE_EXTERNAL_STORAGE 权限一般适用于清理、文件管理、备份或恢复类型的应用,并且该权限会由 Google Play 来控制保护权限不会被滥用。清理类应用可以访问所有的外部存储,但同样也无法访问其他应用的专属目录。在分区存储中,应用的专属目录可以理解为和内部存储是等同的,在 Android 11 中也是不可以去访问的。如果清理类应用可以访问其他应用的专属目录,那么为了保护自己的数据

Dagger 2 get own Room instance

*爱你&永不变心* 提交于 2020-08-05 07:04:45
问题 I want to add a callback to the room database to populate initial data. @Provides @Singleton fun provideRoom(context: Context): MyRoomDatabase { return Room.databaseBuilder(context, MyRoomDatabase::class.java, "my_database") .fallbackToDestructiveMigration() .addCallback(object : RoomDatabase.Callback() { @Override override fun onCreate(db: SupportSQLiteDatabase) { super.onCreate(db) } }) .build() } For that i need the database instance in the callback to access DAO for inserting data. How

【57】kotlin RxKotlin 与 RxAndroid的使用

Deadly 提交于 2020-08-04 19:00:56
RxKotlin 官网地址: https://github.com/ReactiveX/RxKotlin 特点。轻量级 基于RxJava 观察者模式 RxAndroid 官网地址: https://github.com/ReactiveX/RxAndroid 基于Rxjava得扩展卡。可以优雅地处理异步请求 更好得兼容Android特性,如主线程,ui事件 用于RxJava的Kotlin扩展 RxKotlin是一个轻量级的库,它为 RxJava 添加了方便的扩展功能。您可以直接使用RxJava和Kotlin,但是Kotlin具有语言功能(例如 扩展功能 ),可以进一步简化RxJava的使用。RxKotlin旨在保守地在一个集中式库中收集这些便利,并标准化将RxJava与Kotlin一起使用的约定。 官方使用 import io.reactivex.rxjava3.kotlin.subscribeBy import io.reactivex.rxjava3.kotlin.toObservable fun main(args: Array<String>) { val list = listOf("Alpha", "Beta", "Gamma", "Delta", "Epsilon") list.toObservable() // extension function for

【24】kotlin 内部类 匿名内部类

依然范特西╮ 提交于 2020-08-04 18:54:36
package com.yzdzy.kotlin.chapter4.innerclass class Outter { val a: Int = 0 //静态内部类 class Inner { } //非静态内部类 inner class Inner2 { fun hello() { println(a) //Outter 调用成员的a 相当于java得InnerClassJava.this println(this@Outter.a) } } } interface OnClickLisenter { fun onClick() } class View { var onClickLisenter: OnClickLisenter? = null } fun main(args: Array<String>) { var inner = Outter.Inner() val inner2 = Outter().Inner2() val view = View() //匿名内部类 view.onClickLisenter = object : OnClickLisenter { override fun onClick() { TODO("Not yet implemented") } } } 内部类 定义在类内部的类 与成员有相似的访问控制 默认是静态内部类

Android Studio Kotlin开发之ListView

和自甴很熟 提交于 2020-08-04 15:13:40
Android Studio Kotlin开发之ListView Android Studio Kotlin开发之ListView ListView的简单用法 效果图 知识讲解 ArrayAdapter 源代码 MainActivity.kt activity_main.xml 定制ListView界面 效果图 源代码 MainActivity.kt fruitAdapter.kt Fruit.kt activity_main.xml fruit_item.xml Referecces Android Studio Kotlin开发之ListView ListView的简单用法 效果图 知识讲解 ArrayAdapter 在下文源代码中有这样一句 val adapter = ArrayAdapter < String > ( this , android . R . layout . simple_list_item_1 , data ) 这段代码是创建一个数组适配器的代码,里面有三个参数,第一个参数是上下文,就是当前的Activity, 第二个参数是android sdk中自己内置的一个布局,它里面只有一个TextView,这个参数是表明我们数组中每一条数据的布局是这个view,就是将每一条数据都显示在这个view上面;第三个参数就是我们要显示的数据

Realm Android javassist.NotFoundException: io.realm.com_example_realmtest_data_SomethingRealmProxyInterface

╄→гoц情女王★ 提交于 2020-08-04 06:00:08
问题 I was completely new to realm in android, and I started from simple kotlin-project with only one entity which had only one field. open class Something : RealmObject() { @PrimaryKey var id: Long = 0 } I initialized Realm in my Application class: class RealmApp : Application() { override fun onCreate() { super.onCreate() Realm.init(this) val config = RealmConfiguration.Builder().build() Realm.setDefaultConfiguration(config) } } And, of course I added realm plugin: //Project level dependencies {

Returning a value produced in Kotlin coroutine

我与影子孤独终老i 提交于 2020-08-04 05:18:19
问题 I am trying to return a value generated from coroutine fun nonSuspending (): MyType { launch(CommonPool) { suspendingFunctionThatReturnsMyValue() } //Do something to get the value out of coroutine context return somehowGetMyValue } I have come up with the following solution (not very safe!): fun nonSuspending (): MyType { val deferred = async(CommonPool) { suspendingFunctionThatReturnsMyValue() } while (deferred.isActive) Thread.sleep(1) return deferred.getCompleted() } I also thought about

Exception thrown when using @Service in Kotlin

只愿长相守 提交于 2020-08-04 02:48:26
问题 I'm writing an SSM project in Kotlin and this happens as long as I try to annotate a class (a service implementation) with @Service . Tried to code this implementation class in Java instead and it worked all fine. Tried to keep only the necessary overriding methods. open is already added. context:component-scan is configured. java.lang.IllegalStateException: Failed to load ApplicationContext at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext

Base64 support for different API levels

白昼怎懂夜的黑 提交于 2020-08-02 05:38:33
问题 In my Android app build.gradle android { compileSdkVersion 27 defaultConfig { minSdkVersion 16 targetSdkVersion 27 ... } .... } Kotlin code val data = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { Base64.getDecoder().decode(str) } else { Base64.decode(str, Base64.DEFAULT) // Unresolved reference: decode } Obviously, I got compilation error, when using Base64 variant prior to API 24. But how can I support all the API levels and use Base64 as before 24, as after? 回答1: Use android.util