我想在我的应用上显示自定义菜单。但是当我将模型绑定到视图时,菜单就会消失。在帖子的最后,我附上了两张图片。
这是我的活动代码
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_agency_detail)
val toolbar = findViewById(R.id.toolbar) as Toolbar
setSupportActionBar(toolbar)
supportActionBar!!.setDisplayHomeAsUpEnabled(true)
val agencyDao = DaoManager.createDao(getConnection(this), AgencyModel::class.java)
val agency = agencyDao.findLast { item -> item.id == intent.getIntExtra(AgencyDetailActivity.ARG_ITEM_ID, -1) }
binding = DataBindingUtil.setContentView<ActivityAgencyDetailBinding>(this, R.layout.activity_agency_detail)
binding.agency = agency
}
当我删除绑定线时,它可以正常工作,但是使用绑定它不起作用。
它的外观应该是
这就是它的外观
答案 0 :(得分:0)
我找到了解决方案,这很棘手,但很简单。绑定数据后,必须分配工具栏。这是更正后的代码:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val agencyDao = DaoManager.createDao(getConnection(this), AgencyModel::class.java)
val agency = agencyDao.findLast { item -> item.id == intent.getIntExtra(AgencyDetailActivity.ARG_ITEM_ID, -1) }
binding = DataBindingUtil.setContentView<ActivityAgencyDetailBinding>(this, R.layout.activity_agency_detail)
binding.agency = agency
val toolbar = findViewById(R.id.toolbar) as Toolbar
setSupportActionBar(toolbar)
supportActionBar!!.setDisplayHomeAsUpEnabled(true)
}