Kotlin自定义操作栏标题有时会在瞬间显示错误的标题

问题描述 投票:0回答:1

我已经在Kotlin应用中为每个片段创建了自定义操作栏标题。但是有时在显示自定义标题之前,它会在一瞬间显示fragmentname。

这是每个片段中的代码:

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        val binding = inflate<FragmentHomeBinding>(
            inflater,
            R.layout.fragment_home, container, false
        )
        ////
        //some binding
        ////

        return binding.root
    }

 override fun onAttach(context: Context) {
        super.onAttach(context)
        (activity as AppCompatActivity).supportActionBar?.title = "Custom"
    }

    override fun onResume() {
        super.onResume()
        (activity as AppCompatActivity).supportActionBar?.title = "Custom"
    }
android-fragments kotlin android-actionbar
1个回答
0
投票

原来我可以只编辑Navigation.xml中的标签来省去很多麻烦

© www.soinside.com 2019 - 2024. All rights reserved.