Custom Translucent Android ActionBar

前端 未结 7 995
梦如初夏
梦如初夏 2020-11-29 16:19

I\'ve been scouring the interwebs (e.g. Android documentation, answers here, etc.) for the answer to what I thought would be a fairly trivial question. How do you achieve a

7条回答
  •  独厮守ぢ
    2020-11-29 16:37

    Here is how I got this to work:

    1) Request for actionbar overlay programmatically by calling

           getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
    

    this 'requestFeature()' must be requested from your activity 'onCreate()' method before calling for 'setContentView(R.layout.my_layout)':

    2) set the actionbar color by calling setBackgroundDrawable() like so:

    getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#00212121")) );
    

    this method requires either a reference to a drawable or you can also use a color parser to parse a hex color value (first 2 digits are used for alpha channel starting at #00 to #FF)

    Note that I am using actionBarSherlok getSupportActionBar() but this should work with any action bar.

    If you still cant get this to work, try adding this to your theme style

    true
     @style/ActionBar.Transparent.Example
     true
    

提交回复
热议问题