Mer*_*aju 6 android kotlin android-databinding
我在活动中使用片段并使用数据绑定为活动和片段绑定其布局,如下所示:
活动.xml
<?xml version="1.0" encoding="utf-8"?>
<layout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@id/FAB_fromHomeActivity_BottomAppBarAttached"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_add_dark"
android:backgroundTint="@color/colorAccent"
app:layout_anchor="@id/BottomAppBar_fromHomeActivity_Main"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
Run Code Online (Sandbox Code Playgroud)
活动.kt
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
mBinding = DataBindingUtil.setContentView(this, R.layout.activity)
}
Run Code Online (Sandbox Code Playgroud)
片段.kt
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
// Inflate the layout for this fragment
mBinding = DataBindingUtil.inflate(inflater, R.layout.fragment_goals, container, false)
return mBinding.root
}
Run Code Online (Sandbox Code Playgroud)
有没有办法使用片段中的绑定访问活动中的 FAB?(例如类似 mBinding.parent.FAB 的东西)
我找不到这方面的任何信息。任何人都可以帮忙吗?
| 归档时间: |
|
| 查看次数: |
1177 次 |
| 最近记录: |