Navigation Drawer Below Transparent Actionbar

天大地大妈咪最大 提交于 2019-12-10 22:29:34

问题


I'm getting a transparent Actionbar by using the following code that @GunnarKarlsson shows here: Transparent Actionbar: custom tabcolor

getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
ActionBar actionBar = getActionBar();
actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#330000ff")));
actionBar.setStackedBackgroundDrawable(new ColorDrawable(Color.parseColor("#550000ff")));

It works pretty much perfectly with the exception of how it affects the navigation drawer. Instead of it sliding out directly below the action bar it slides over it. Below are two images to clarify what I mean. I'm trying to figure out how to achieve the placement of the navigation drawer from the first image but retain the transparency shown on the second. Has anyone come across a similar problem?


回答1:


To achieve that you have to calculate Action Bar height and set marginTop to your navigation drawer. Use this method to calculate Action bar height:

 public static int CalculateActionBar(Context context){
        // Calculate ActionBar height
        TypedValue tv = new TypedValue();
        if (context.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {

           int mActionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data, context.getResources().getDisplayMetrics());
           return mActionBarHeight;
        }
        return 0;
    }

Then from java set Margin Top to your Navigation Drawer Object.

Doing this you will achieve a Navigation Drawer below Action Bar



来源:https://stackoverflow.com/questions/24139846/navigation-drawer-below-transparent-actionbar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!