透明动作栏下方的导航抽屉

snl*_*lan 3 transparency android titlebar android-actionbar navigation-drawer

我使用@GunnarKarlsson在此处显示的以下代码获取透明的Actionbar:透明操作栏:自定义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")));
Run Code Online (Sandbox Code Playgroud)

它的工作方式非常完美,除了它如何影响导航抽屉.它不是直接滑动到动作栏下方,而是滑过它.下面是两张图片来澄清我的意思.我试图弄清楚如何从第一张图像中实现导航抽屉的放置,但保留第二张图像上显示的透明度.有没有人遇到过类似的问题?

在此输入图像描述

在此输入图像描述

Ult*_*o_m 5

要实现这一点,您必须计算操作栏高度并将marginTop设置为导航抽屉.使用此方法计算操作栏高度:

 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;
    }
Run Code Online (Sandbox Code Playgroud)

然后从java设置Margin Top到你的导航抽屉对象.

这样做,您将在Action Bar下方实现导航抽屉

  • ..或使用`"?android:attr/actionBarSize"`来指定XML中的大小. (3认同)