Ale*_*Wih 11 android android-studio android-viewbinding
Android 中的View Binding被大力提倡作为findViewById()
Kotlin 扩展甚至是 Kotlin 扩展的更好替代品,但由于某种原因,最基本的功能,如View
在 Android Studio 的布局编辑器中按其 ID搜索 a的用法不起作用。
即使在官方 Ach 组件示例存储库中的视图绑定示例中,它也不起作用。
我们这里有:
fragment_blank.xml
具有TextView
与IDtextViewFragment
如下:<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>
Run Code Online (Sandbox Code Playgroud)
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
}
Run Code Online (Sandbox Code Playgroud)
关于如何View
从布局编辑器中通过ID搜索此类用法的任何想法?
无法相信视图绑定缺少这样的基本功能。
Android Studio 版本4.0.1
。
摇篮版6.6.1
。
Android Gradle 插件版4.0.1
归档时间: |
|
查看次数: |
238 次 |
最近记录: |