package `my`.app.ui
import `my`.app.R
import android.os.Bundle
import androidx.fragment.app.Fragment
class Support : Fragment(R.layout.appui) {
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
activity.apply {
this?.actionBar?.title = "title"
this?.actionBar?.subtitle = "subtitle"
}
}
}
NavigationUI
不支持设置标题或副标题?
以下是用于项目的依赖项
- implementation 'androidx.core:core-ktx:1.3.0'
- implementation 'androidx.appcompat:appcompat:1.1.0'
- implementation 'androidx.navigation:navigation-fragment-ktx:2.3.0'
- implementation 'androidx.navigation:navigation-ui-ktx:2.3.0'
答案 0 :(得分:1)
您可以在设置方法之后添加OnDestinationChangedListener
来设置标题:
navController.addOnDestinationChangedListener { controller, destination, arguments ->
if (destination.id == R.id.nav_xxx){
supportActionBar?.title = "My Title"
}
//.....
}