You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android中隐藏BottomAppBar和FAB后重显时圆角凹槽消失如何解决?

问题原因

直接修改BottomAppBar和FloatingActionButton的visibility属性,会跳过Material组件内部针对FAB凹槽的重绘计算逻辑,导致重新显示控件时凹槽效果没有重新渲染。

解决方案

  1. 优先使用Material组件自带的hide()/show()方法替代直接修改visibility属性,该方法内部会自动触发凹槽的重绘逻辑:
override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    (activity as MainActivity).let {
        it.toolbarText = "Olá " + it.user?.name
        it.appbar.setExpanded(true)
        // 替换原有直接设置GONE的逻辑
        it.binding.fabNewIssue.hide()
        it.binding.bottomBar.hide()
        it.binding.mainFragmentContainer.setPadding(0,0,0, 
                  Utils().convertDpToPixel(60f,requireContext()).toInt())
    }
}
  1. 在需要恢复显示BottomBar和FAB的Fragment的onResume生命周期中添加恢复逻辑,同时还原Fragment容器的底部padding:
override fun onResume() {
    super.onResume()
    (activity as MainActivity).let {
        // 调用自带show方法恢复控件显示,自动触发凹槽重绘
        it.binding.fabNewIssue.show()
        it.binding.bottomBar.show()
        // 还原容器底部padding
        it.binding.mainFragmentContainer.setPadding(0,0,0,0)
        // 如仍未显示凹槽,可主动调用invalidate强制重绘
        it.binding.bottomBar.invalidate()
    }
}
  1. 若上述方案仍无效,可主动重新设置一次FAB的对齐模式,强制触发凹槽计算逻辑:
it.binding.bottomBar.fabAlignmentMode = BottomAppBar.FAB_ALIGNMENT_MODE_CENTER

内容的提问来源于stack exchange,提问作者João Pitrez

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.22 04:54:01