小编And*_*Dev的帖子

如何在Android中获取实质性的图标按钮?

如何在android中获取材质按钮?我已经尝试过此代码,但是不知道如何包含这样的图像:

<com.google.android.material.button.MaterialButton
    android:id="@+id/material_button"
    style="@style/Widget.MaterialComponents.Button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Add to Cart"/>
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

android android-button material-design

5
推荐指数
1
解决办法
129
查看次数

AlertDialog 不显示带有 Material 组件主题的项目

如何在 AlertDialog.Only AlertDialog 中显示项目,没有任何项目我正在尝试下面的代码,但这似乎不起作用:

CharSequence[] choices = {"Choice1", "Choice2", "Choice3"};

AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context)
.setTitle(context.getString(R.string.title))
.setPositiveButton(context.getString(R.string.Ok), null)
                            .setNeutralButton(context.getString(R.string.Cancel), null)
.setSingleChoiceItems(choices, 1, null);

AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
Run Code Online (Sandbox Code Playgroud)

我正在使用材料组件样式:

<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

android android-alertdialog material-design material-components material-components-android

1
推荐指数
1
解决办法
893
查看次数

使用 async &amp; await 从房间数据库获取数据

我正在尝试使用async & awaitinside从 Room Database 获取数据,Coroutine Scope但在返回值时遇到问题。

这是我的代码:

fun getUserFromDB():Profile {
    val profileDao = AppDatabase.getDatabase(context).getProfileDao()
    CoroutineScope(Dispatchers.IO).launch {
        return profileDao.getUserProfile().await()
    }
}
Run Code Online (Sandbox Code Playgroud)

道:

@Query("SELECT * FROM PROFILE LIMIT 1")
suspend fun getUserProfile():Deferred<Profile>
Run Code Online (Sandbox Code Playgroud)

在这里我想从方法返回 userProfile 但我不能在范围内这样做,如果我从Coroutine scope.

注意:我不是在这里遵循 MVVM 模式,而是做一个简单的例子。

android deferred kotlin android-room kotlin-coroutines

1
推荐指数
1
解决办法
2404
查看次数

在扩展函数中传递带参数的函数(kotlin)

  • 我正在尝试Extension function使用处理程序在 android 中创建一个,但面临问题:

扩展乐趣代码:

fun delayTask(millis: Long, myFunction: (data:String) -> Unit) {
    Handler().postDelayed({
        myFunction(data)    //why error is of data here
    }, millis)
}
Run Code Online (Sandbox Code Playgroud)

像这样调用:

 delayTask(500, ::function)
Run Code Online (Sandbox Code Playgroud)
  • 获取错误未解决的参考:数据

android kotlin kotlin-extension

-2
推荐指数
1
解决办法
1109
查看次数