问题
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