Android Theme.NoTitleBar不起作用

Android Theme.NoTitleBar doesnot work

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

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

问题:

即使我放置

android:Theme.Light.NoTitleBar

我的清单中有一个标题栏的空白。 因此,我的整个布局被向下推。

我尝试使用

requestWindowFeature(Window.FEATURE_NO_TITLE);

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

但标题栏空间仍未删除。

这是应用程序的外观

enter image description here

enter image description here

我认为这是由于可容纳主要滑动布局的Custom LinearLayout类引起的。 但是我无法从自定义布局类中删除标题栏空间。
提出更好的解决方案。

自定义布局类

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
   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);

      }
     }


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

1
2
3
<activity android:name=".MainActivity"
      android:label="@string/app_name"
      android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen">


最后,我能够删除标题栏空间。
事实证明,包括这个标签

1
android:theme="@android:style/Theme.Light.NoTitleBar.Fullscreen"

清单中的应用程序上的问题使应用程序全屏显示并更正了该问题。但是我希望状态栏在我的应用程序中可见。
因此,我不得不在标题栏空间未减少的android版本上妥协了状态栏,并使其与其他版本相同。
所以这是我解决的方法。

在清单中,我将代码保持原样

1
android:theme="@android:style/Theme.Light.NoTitleBar"

删除应用程序中的标题栏

在使用自定义线性布局的活动中,我检查了android版本,并在小于和等于Gingerbread的版本上将应用全屏显示。

1
2
3
4
5
6
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD)
{
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,  
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}

在清单文件中尝试

1
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"

值\ style.xml
定义名称和主题
例如。,

然后转到您的androidmainfest.xml
在活动中添加..
android:theme =" @ style / NoActionBar"


看来Theme.NoTitleBar仅在应用于整个应用程序时才起作用,而不是活动本身。因此,将其放在application标签(清单中)中:

1
 

然后,向每个活动中添加所需的任何自定义样式。

希望能帮助到你。


希望这对您有帮助。

1
2
3
4
5
this.requestWindowFeature(Window.FEATURE_NO_TITLE);

// Remove notification bar
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
    WindowManager.LayoutParams.FLAG_FULLSCREEN);

将android:主题属性添加到您的AndroidManifest.xml中:

1