我有一个util Kotlin类,我在其中设置工具栏标题,隐藏或显示工具栏取决于片段:
class MyToolbarUtils() {
fun hideToolbar(activity: Activity) {
(activity as MainActivity).supportActionBar!!.hide()
}
fun showToolbar(activity: Activity, tag: String) {
setToolbarTitle(tag, activity)
(activity as MainActivity).supportActionBar!!.show()
}
fun setToolbarTitle(tag: String, activity: Activity) {
var title = ""
when (tag) {
"Main_fragment" -> title = activity.resources.getString(R.string.Main_screen)
"Add_note" -> title = activity.resources.getString(R.string.Add_note)
}
activity.title = title
}
}
how to call showToolbar(...) from Fragment?
I just tried MyToolbarUtils.showToolbar(..)
but it can not be possible
only one way I discover is:
val setToolbarTitle = MyToolbarUtils()
setToolbarTitle.showToolbar(activity, tag)
but there must be better way to do that..