android - 在 Android Studio 中,XML 布局中视图 ID 的“查找用法”操作不适用于 Android 视图绑定
问题描述
Android 中的View Binding被大力提倡作为一个更好的替代findViewById()
甚至 Kotlin 扩展,但出于某种原因,在 Android Studio 的布局编辑器中通过 ID 搜索 a 的使用的最基本功能View
不起作用。
它甚至在官方 Acrh 组件示例存储库中的视图绑定示例中也不起作用。
在这里,我们有:
fragment_blank.xml
带有TextView
ID的XML 布局textViewFragment
如下:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".InflateFragment">
<TextView
android:id="@+id/textViewFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/hello_blank_fragment" />
</FrameLayout>
- 使用视图绑定
InflateFragment.kt
将文本设置为此的片段:TextView
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// Inflate the layout for this fragment
val binding = FragmentBlankBinding.inflate(inflater, container, false)
fragmentBlankBinding = binding
binding.textViewFragment.text = getString(R.string.hello_from_vb_inflatefragment)
return binding.root
}
关于如何通过View
布局编辑器中的 ID 搜索此类用法的任何想法?
无法相信视图绑定缺少这样的基本功能。
安卓工作室版本4.0.1
。
摇篮版本6.6.1
。
Android Gradle 插件版本4.0.1