Android Theme.NoTitleBar不起作用

lil*_*'ms 2 android titlebar android-layout android-theme

我在我的应用程序中有一个像滑动菜单栏的Facebook,其中应用程序的两个内容和主要布局由自定义布局类处理.

我想删除我的应用程序的标题栏

问题:

即使我放置

机器人:Theme.Light.NoTitleBar

在我的清单中,标题栏有一个空白区域.由此我的整个布局被推倒了.

我试过用

requestWindowFeature(Window.FEATURE_NO_TITLE);

getWindow()setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN).

但仍然没有删除标题栏空间.

这就是应用程序的样子

在此输入图像描述

在此输入图像描述

我认为这是由于Custom LinearLayout类保存了主滑动布局.但我无法从自定义布局类中删除标题栏空间.建议更好的解决方案.

自定义布局类

   public class MainLayout extends LinearLayout {
        public MainLayout(Context context, AttributeSet attrs) {
            super(context, attrs);
        }
        public MainLayout(Context context) {
            super(context);
        }

        // Overriding LinearLayout core methods
        // layout based on the children
        @Override
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            super.onMeasure(widthMeasureSpec, heightMeasureSpec);

            mainLayoutWidth = MeasureSpec.getSize(widthMeasureSpec);
            menuRightMargin = mainLayoutWidth * 10 / 100;
        }

        @Override
        protected void onAttachedToWindow() {
            super.onAttachedToWindow();
            menu = this.getChildAt(0);
            content = this.getChildAt(1);   
            content.setOnTouchListener(new OnTouchListener() {
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    return MainLayout.this.onContentTouch(v, event);
                }
            });

@Override
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
        if(changed) {
           LayoutParams contentLayoutParams = (LayoutParams)content.getLayoutParams();
            contentLayoutParams.height = this.getHeight();
            contentLayoutParams.width = this.getWidth(); LayoutParams menuLayoutParams = (LayoutParams)menu.getLayoutParams();
        menuLayoutParams.width = this.getWidth() - menuRightMargin;          
        }

        menu.layout(left, top, right - menuRightMargin, bottom);
        content.layout(left + contentXOffset, top, right + contentXOffset, bottom);

      }
     }
Run Code Online (Sandbox Code Playgroud)

San*_*osh 5

你可以直接在活动的清单文件中指定

<activity android:name=".MainActivity"
      android:label="@string/app_name"
      android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen">
Run Code Online (Sandbox Code Playgroud)