gpt4 book ai didi

android-activity - getDecorView 方法返回 View 包括 Lollipop 上的导航栏 View ?

转载 作者:行者123 更新时间:2023-12-04 02:38:37 25 4
gpt4 key购买 nike

我用 SlidingMenu实现我的滑入式菜单。

代码是

private void initSlidingMenu()
{
// configure the SlidingMenu
menu = new SlidingMenu(this);
menu.setMode(SlidingMenu.LEFT);
menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
menu.setShadowWidthRes(R.dimen.shadow_width);
// menu.setShadowDrawable(R.drawable.shadoew);
menu.setBehindOffsetRes(R.dimen.slidingmenu_offset);
// menu.setFadeDegree(0.35f);
menu.attachToActivity(this, SlidingMenu.SLIDING_WINDOW);
menu.setMenu(R.layout.menu_main_sliding);
}


然后我遇到了一个问题是我在导航栏后面的布局。
my bottom view behind of navigation bar my bottom layout behind of navigation bar

我将 SlidingMenu.SLIDING_WINDOW 更改为 SlidingMenu.SLIDING_CONTENT。
它的工作原理,但操作栏总是在顶部。

查看SlidingMenu的源代码,我发现这段代码添加了slidingmenu。
    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);
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;
}

我该如何解决?
此错误仅在 Android 5.0 Lollipop 中发现。

最佳答案

GitHub 上的 SlidingMenu 已打开相同 issue .

private int getNavigationBarHeight() { 
Resources resources = getResources();
int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
if (resourceId > 0) {
return resources.getDimensionPixelSize(resourceId);
}
return 0;
}

@Override
public void onCreate(Bundle savedInstanceState) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
int navBarHeight = getNavigationBarHeight();
findViewById(R.id.base_frame).setPadding(0, 0, 0, navBarHeight);
findViewById(R.id.menu_frame).setPadding(0, 0, 0, navBarHeight);
}
}

关于android-activity - getDecorView 方法返回 View 包括 Lollipop 上的导航栏 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27165690/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com