Make Toolbar transparent

前端 未结 4 777
不知归路
不知归路 2021-01-30 18:43

create_account.xml




        
4条回答
  •  梦如初夏
    2021-01-30 19:15

    That is my version of how to get the transparent Toolbar without shadow in AppBarLayout. The major problem with the above solutions was when I made the toolbar transparent, the shadow was still cast under it. To make the transparent toolbar with the back navigationIcon in Fragment:

    layout_transparent_toolbar_fragment.xml:

    
    
        
    

    and in TransparentToolbarFragment:

    override fun onCreateView(inflater: LayoutInflater, vg: ViewGroup?, savedInstanceState: Bundle?): View? {
        val layout = inflater.inflate(R.layout.layout_transparent_toolbar_fragment, vg, false)
        val toolbar = layout.findViewById(R.id.toolbar) as Toolbar
        val appBar = layout.findViewById(R.id.general_appbar) as AppBarLayout
        appBar.outlineProvider = null
        val appCompatActivity = (activity as AppCompatActivity)
        appCompatActivity.setSupportActionBar(toolbar)
    
        val actionBar = appCompatActivity.getSupportActionBar()
        if (actionBar != null) actionBar!!.setDisplayHomeAsUpEnabled(true)
        toolbar.setNavigationOnClickListener { appCompatActivity.finish() }
    
        return layout
    }
    

    Actually, the line

    appBar.outlineProvider = null
    

    does the job of hiding the toolbar shadow.

提交回复
热议问题