因此,每当创建活动时,我都会设置自定义指标图标,如下所示:
private fun setupActionBar() {
setSupportActionBar(toolbar)
supportActionBar?.apply {
setDisplayShowTitleEnabled(false)
setHomeButtonEnabled(true)
setHomeAsUpIndicator(R.drawable.custom_drawable)
setDisplayHomeAsUpEnabled(true)
}
}
我的问题是-如何将setHomeAsUpIndicator
更改为片段的默认后退箭头?
答案 0 :(得分:4)
在片段中的onAttach(context:Context)函数中,您可以访问actionBar
override fun onAttach(context : Context) {
if (context is YourParentActivity) {
val activity = context as YourParentActivity
activity.supportActionBar?.apply{
setDisplayShowTitleEnabled(false)
setHomeButtonEnabled(true)
setHomeAsUpIndicator(R.drawable.your_deafault_back_arrow)
setDisplayHomeAsUpEnabled(true)
//Here Customize your action bar as much as you want
}
}
}
享受编码:如果您还有其他问题,请告诉我