gpt4 book ai didi

Android 数据绑定(bind) SetSupportActionBar

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:59:47 37 4
gpt4 key购买 nike

您好,我想知道是否有使用 Android 数据绑定(bind)库的此功能的 xml 标记,或者如何在没有 findViewById() 方法的情况下实现此功能

谢谢

最佳答案

您可以访问工具栏的实例using views by id功能

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/AppTheme.PopupOverlay" />

然后在你的onCreate()上方法执行以下操作

ActivityGalleryBinding binding = DataBindingUtil
.setContentView(this, R.layout.activity_gallery);
binding.setViewModel(new GalleryModel(this));
//set it like this
setSupportActionBar(binding.<location>.<of>.<your>.toolbar);

如果您的工具栏位于其他 xml 组件中(用 <include/> 引用),您仍然可以访问它,只要您提供和 @id<include/>

关于Android 数据绑定(bind) SetSupportActionBar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34636934/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com