进过查找资料知道,android的页面置顶到状态栏只支持linearlayout和textview,而slidingmenu继承的是RelativeLayout,所以需要在RelativeLayout根部局下插入一个textview,修改attachToActivity方法,如下图:
switch (slideStyle) {
case SLIDING_WINDOW:
mActionbarOverlay = false;
ViewGroup decor = (ViewGroup) activity.getWindow().getDecorView();
ViewGroup decorChild = (ViewGroup) decor.getChildAt(0);
// save ActionBar themes that have transparent assets
decorChild.setBackgroundResource(background);
decor.removeView(decorChild);
// decor.addView(this); 注释掉
setContent(decorChild);
//解决侧边栏沉浸问题
RelativeLayout relativeLayout = new RelativeLayout(activity);
TextView textView = new TextView(activity);
textView.setFitsSystemWindows(true);
relativeLayout.addView(textView);
relativeLayout.addView(this);
decor.addView(relativeLayout);
break;
case SLIDING_CONTENT:
mActionbarOverlay = actionbarOverlay;
// take the above view out of
ViewGroup contentParent = (ViewGroup)activity.findViewById(android.R.id.content);
View content = contentParent.getChildAt(0);
contentParent.removeView(content);
contentParent.addView(this);
setContent(content);
// save people from having transparent backgrounds
if (content.getBackground() == null)
content.setBackgroundResource(background);
break;
}
}