我正在学习Kotlin协同程序.我读过这runBlocking
是桥接同步和异步代码的方法.但是如果runBlocking
停止UI线程,性能提升是多少?例如,我需要在Android中查询数据库:
val result: Int
get() = runBlocking { queryDatabase().await() }
private fun queryDatabase(): Deferred<Int> {
return async {
var cursor: Cursor? = null
var queryResult: Int = 0
val sqlQuery = "SELECT COUNT(ID) FROM TABLE..."
try {
cursor = getHelper().readableDatabase.query(sqlQuery)
cursor?.moveToFirst()
queryResult = cursor?.getInt(0) ?: 0
} catch (e: Exception) {
Log.e(TAG, e.localizedMessage)
} finally {
cursor?.close()
}
return@async queryResult
}
}
Run Code Online (Sandbox Code Playgroud)
查询数据库会停止主线程,所以它似乎需要与同步代码相同的时间?如果我错过了什么,请纠正我.
我有一个包含多个皮肤的应用程序。在我定义的一个皮肤中android:colorBackground
,然后我想在 XML 布局中将此颜色设置为 ViewGroup 背景颜色。我该怎么做?是否可以?或者它只是系统使用的某些属性?
<style name="SkinDefault" parent="@style/_SkinXYZ">
<item name="android:colorBackground">@color/skin_default_color_background</item>
<item name="colorOnBackground">@color/skin_default_color_on_background</item>
</style>
Run Code Online (Sandbox Code Playgroud) android android-theme android-attributes material-components-android
我正在尝试从现有的加载程序/内容提供程序迁移到Room。我需要一些列以具有默认值。在Kotlin中添加默认值,例如,var columnName: Int = 0
但是当我检查RoomDatabase_Impl
它时,会忽略架构创建中的Kotlin默认值。如何为Room列引入DEFAULT值?
如何将BottomSheetDialogFragment
主题与其他主题结合?
我的应用程序具有使用主题制作的皮肤。BottomSheetDialogFragment
应该有圆角,我使用以下方法实现:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setStyle(BottomSheetDialogFragment.STYLE_NORMAL, R.style.CustomBottomSheetDialogTheme) /* hack to make background transparent */
}
Run Code Online (Sandbox Code Playgroud)
然后在styles.xml
:
<style name="CustomBottomSheetStyle" parent="Widget.Design.BottomSheet.Modal">
<item name="android:background">@android:color/transparent</item>
</style>
<style name="CustomBottomSheetDialogTheme" parent="Theme.MaterialComponents.Light.BottomSheetDialog">
<item name="bottomSheetStyle">@style/CustomBottomSheetStyle</item>
</style>
Run Code Online (Sandbox Code Playgroud)
但是如果我从 扩展,Theme.MaterialComponents.Light.BottomSheetDialog
我不会得到我在皮肤主题中定义的配色方案。
那么问题来了:如何在皮肤主题里面定义Dialog主题呢?
android android-theme bottom-sheet material-components material-components-android
当 TextView 位于 ConstraintLayout 内时,如何在 TextView 中对齐文本?我无法使用layout_width="match_parent
. 试过了,不起作用:(
android:gravity="start"
android:textAlignment="gravity"
Run Code Online (Sandbox Code Playgroud) Google 文档说:
此事件仅由包含Firebase SDK的应用程序版本触发。注意:不会自动跟踪已付费的应用购买收入,订阅收入(仅适用于Android)和退款。您报告的收入可能与您在Google Play开发者控制台中看到的值不同。标记为无效或沙箱(测试)的事件将被忽略。仅iOS事件被标记为沙箱。进一步了解如何测试Google Play帐单。
换句话说,在Android中,只有订阅事件不会被自动跟踪。有没有办法追踪他们?您有任何实施示例吗?
android ×6
kotlin ×2
material-components-android ×2
android-room ×1
bottom-sheet ×1
firebase ×1
google-play ×1
sqlite ×1
textview ×1