我正在尝试使用 的实例MutableState作为属性委托。
这是我所拥有的:
val countState = remember { mutableStateOf(0) }
这就是我想要的:
var count by remember { mutableStateOf(0) }
但是,当我使用by关键字时,我收到编译器错误:
Type 'TypeVariable(T)' has no method 'getValue(Nothing?, KProperty<*>)' and thus it cannot serve as a delegate
出了什么问题?
Use legacy android.support libraries创建新项目时是否应该选择该选项?如果我不选择此选项会怎样?

我面临与Github 问题相同的问题,但适用于不同的用例。我正在尝试添加应用程序的多个实例:此处的示例代码。
添加域后,我收到相同的错误:
Domain www.app.com was not found in your AWS account.
Run Code Online (Sandbox Code Playgroud)
因此,为了实现多个实例,我尝试将 env-prod 文件更改为bucket="prod-appname". 这已部署,但是当我将 env-stage 文件添加到 时bucket="stage-appname",这会创建一个新存储桶,但会将其部署到相同的 CloudFront URL。有没有办法修复它们中的任何一个,以便我可以实现多个实例?
提前致谢
javascript amazon-web-services amazon-cloudfront serverless-framework next.js
我有一个看起来像这样的布局:
Row {
...
Box(
modifier = Modifier
.fillMaxHeight()
.width(50.dp)
) {
AnimatedVisibility(
visible = isSelected && selectedAnimationFinished,
enter = fadeIn(),
exit = fadeOut()
) {
...
}
}
}
Run Code Online (Sandbox Code Playgroud)
但我收到编译时错误:
fun RowScope.AnimatedVisibility(visible: Boolean, modifier: Modifier = ..., enter: EnterTransition = ..., exit: ExitTransition = ..., content: AnimatedVisibilityScope.() -> Unit): Unit' can't be called in this context by implicit receiver. Use the explicit one if necessary
Run Code Online (Sandbox Code Playgroud)
看起来 Kotlin 发现AnimatedVisibility函数不明确,因为 Compose 公开了多个AnimatedVisibility具有相同签名的函数:有一个fun AnimatedVisibility没有接收器,一个fun RowScope.AnimatedVisibility …
我使用我自己的主题创建了一个 SplashScreen...
<style name="AppTheme.Launcher">
<item name="android:windowBackground">@drawable/splash_test</item>
</style>
Run Code Online (Sandbox Code Playgroud)
...应用程序加载时应用为应用程序的主主题...
android:theme="@style/AppTheme.Launcher"
Run Code Online (Sandbox Code Playgroud)
...然后在启动的Activity的onCreate中更改为AppTheme:
setTheme(R.style.AppTheme);
super.onCreate(savedInstanceState);
Run Code Online (Sandbox Code Playgroud)
一切正常,但我有一个有趣的问题。所有的屏幕预览都使用Launcher主题,现在看起来像:
我就是不能这样工作。=)
我怎样才能避免这个“问题”呢?
我创建了一个自定义对话框主题,如下所示:
<style name="dialogLight" parent="Theme.AppCompat.Light.Dialog">
<item name="android:windowBackground">attr/theme_dialogBackground</item>
</style>
Run Code Online (Sandbox Code Playgroud)
然而,当我运行应用程序时,dialog背景是默认设置(在一台设备上是透明的,在另一台设备上是黑色的).
但是,如果我更改android:windowBackground为android:background,android:background则会看到正确的行为,并且对话框中所有视图的默认背景将成为指定的值.
将android:windowBackground的值更改为@drawable或@color工作.
我知道android:windowBackground和之间有什么区别android:background,并且使用android:background不是我需要的,因为我只想改变窗口背景颜色.
那么为什么android:windowBackground不被应用呢?
我正在将一个应用程序迁移到 MVVM 和干净的架构,但我遗漏了这个难题的一部分。
问题域:
列出设备上的所有应用程序并将其显示在 Fragment / Activity 中
设备应用程序由其包名称表示:
data class DeviceApp(val packageName: String)
设备应用程序的列出方式如下:
private fun listAllApplications(context: Context): List<DeviceApp> {
val ans = mutableListOf<DeviceApp>()
val packageManager: PackageManager = context.applicationContext.packageManager
val packages = packageManager.getInstalledApplications(PackageManager.GET_META_DATA)
for (applicationInfo in packages) {
val packageName = applicationInfo.packageName
ans.add(DeviceApp(packageName))
}
return ans
}
Run Code Online (Sandbox Code Playgroud)
据我了解,调用listAllApplications()应该在“域层”内的用例中完成,该用例由ViewModel.
但是listAllApplications收到一个Context, 并且域层应该只是纯代码。
在干净的架构/MVVM 中,我应该放在哪一层listAllApplications(context)?
更一般地说,ViewModel 应如何与需要Context(位置等)的 Android 框架 API 进行交互?
我正在尝试使用以下Barrier视图ConstraintLayout:
<android.support.constraint.Barrier
android:id="@+id/buttonBarrier"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:barrierDirection="top"
app:constraint_referenced_ids="answer1Button,answer2Button"
/>
Run Code Online (Sandbox Code Playgroud)
它在 IDE 中运行良好,并且我收到 Barrier-specific lint 消息。但是当我运行该应用程序时,它在尝试膨胀包含 Barrier 的布局时崩溃:
java.lang.ClassNotFoundException: Didn't find class "android.support.constraint.Barrier"
Run Code Online (Sandbox Code Playgroud)
我正在使用 AndroidX ConstraintLayout 1.1.3:
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
Run Code Online (Sandbox Code Playgroud)
这里发生了什么事?
现在是 2020 年,在 iOS 最终添加对小部件的支持后,小部件再次风靡一时。但是,Android Widgets 似乎自 2012 年以来就没有更新过。
RemoteViews 对象(以及相应的 App Widget)可以支持以下布局类:
- 框架布局
- 线性布局
- 相对布局
- 网格布局
这意味着,没有 ConstraintLayout,没有 RecyclerView,没有 AndroidX。我不想回到 ListView 的黑暗日子。
Android 开发者网站上的文档真的仍然是当今开发 Android Widget 的最佳实践吗?有没有人有在 AndroidX 世界中制作小部件的经验?是否有任何类型的 3rd 方 API 可以使体验不那么痛苦?
我有一个RecyclerView,其中项目视图是通过在自定义视图中膨胀布局来创建的ConstraintLayout,其根为 。
当我将子视图设置为具有宽度时,wrap_content它工作正常。
但是当我将第二个子视图设置为具有宽度0dp(“match_constraint”)时,奇怪的事情发生了。
这是我的项目布局:
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:id="@+id/myTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="TextView"
/>
<TextView
android:id="@+id/myTextView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:textColor="@color/text_color_dark_primary"
android:textSize="15sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/myTextView"
tools:text="TextView"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
当 myTextView2 有 width 时wrap_content,一切都很好。但是当我成功时0dp,所有的地狱都崩溃了。
该问题仅发生在第二个 TextView 上 - 第一个 TextView 可以具有宽度wrap_content或0dp,并且都按预期工作。但是当第二个 TextView 有 width 时0dp,就会出现不同的问题:
myTextView: wrap_content, myTextView1: wrap_content - 没问题
myTextView: 0dp, …
在 Compose 中,我们AnnotatedString使用Spanned. 但是,我似乎无法找到一种方法来使用SpanStyle复制relativesizespan的行为。
我可以看到的相关选项SpanStyle是:
TextGeometricTransform仅执行 X 变换,并且我需要在 X 和 Y 方向上缩放文本。有人可以分享一些见解吗?
android ×10
kotlin ×2
android-mvvm ×1
androidx ×1
javascript ×1
legacy-code ×1
mvvm ×1
next.js ×1
themes ×1
use-case ×1
widget ×1