大飞

大飞 关注TA

挑战一切!

大飞

大飞

关注TA

挑战一切!

  •  世界的顶端
  • 混口饭吃
  • 写了333,609字

该文章投稿至Nemo社区   Android  板块 复制链接


解决slidingmenu侧边栏无法沉浸问题

发布于 2017/03/06 07:53 1,343浏览 0回复 1,361

   进过查找资料知道,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;
		}
	}


本文标签
 {{tag}}
点了个评