如何在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)
如何在 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
我正在尝试使用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 模式,而是做一个简单的例子。
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)