【发布时间】:2022-08-17 00:13:07
【问题描述】:
我正在尝试使用 databinding 和 setContent() 在活动中现有的 XML 中使用 Jetpack Compose UI 元素。
这是 xml 元素:
<androidx.compose.ui.platform.ComposeView
android:id=\"@+id/save_btn_compose\"
android:layout_width=\"match_parent\"
android:layout_height=\"wrap_content\"
/>
我在 kotlin 活动文件中使用了这个语法,它运行顺利:
binding.ComposeView.setContent{
MainActionButtonKt.MainActionButton(true, R.string.complete_job, R.drawable.ic_complete_btn_icon, false);
}
java活动文件的等价物是什么?我试图这样做:
binding.saveBtnCompose.setContent((composer, integer) -> {
MainActionButton(true, R.string.complete_job, R.drawable.ic_complete_btn_icon, false);
return null;
});
但我得到一个编译错误:
required: boolean, int, Integer, boolean, Composer, int, int
found: boolean, int, int, boolean
reason: actual and formal argument lists differ in length
我究竟做错了什么?谢谢 !
-
Compose 只是 kotlin,我猜你不能使用任何从 java 注释的
@Composable。
标签: java kotlin android-jetpack-compose