Android的Theme.NoTitleBar不列入工作 [英] Android Theme.NoTitleBar doesnot work
问题描述
我有一个像我的应用程序在应用程序的两个内容和主要布局是由自定义布局类处理的滑动菜单栏中的Facebook。
我想删除我的应用程序的工具栏
问题:
虽然我把
安卓Theme.Light.NoTitleBar
块引用>在我的清单有标题栏的空白区域。由于这我的整个布局向下推动。
我已经尝试使用
requestWindowFeature(Window.FEATURE_NO_TITLE);
块引用>和
getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
块引用>但仍标题栏的空间不会被删除。
这是应用程序的样子
我认为这是由于持有的主要滑动布局定制的LinearLayout类引起的。但我无法删除从自定义布局类的标题栏的空间。
推荐一个更好的解决方案。自定义布局类
公共类MainLayout扩展的LinearLayout {
公共MainLayout(上下文的背景下,ATTRS的AttributeSet){
超(背景下,ATTRS);
}
公共MainLayout(上下文的背景下){
超级(上下文);
} //重写的LinearLayout核心方法
//基于所述儿童布局
@覆盖
保护无效onMeasure(INT widthMeasureSpec,诠释heightMeasureSpec){
super.onMeasure(widthMeasureSpec,heightMeasureSpec); mainLayoutWidth = MeasureSpec.getSize(widthMeasureSpec);
menuRightMargin = mainLayoutWidth * 10/100;
} @覆盖
保护无效onAttachedToWindow(){
super.onAttachedToWindow();
菜单= this.getChildAt(0);
含量= this.getChildAt(1);
content.setOnTouchListener(新OnTouchListener(){
@覆盖
公共布尔onTouch(视图V,MotionEvent事件){
返回MainLayout.this.onContentTouch(ⅴ,事件);
}
});@覆盖
保护无效onLayout(布尔变化,诠释离开,诠释顶部,右诠释,诠释底部){
如果(改变){
的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(左,上,右 - menuRightMargin,底部);
content.layout(左+ contentXOffset,上,右+ contentXOffset,底部); }
}
解决方案最后我能够删除标题栏的空间。
事实证明,包括这个标记安卓主题=@安卓风格/ Theme.Light.NoTitleBar.Fullscreen
在清单应用程序发出的全屏应用程序并纠正问题。但我想在状态栏是在我的应用程序可见。
于是,我只好妥协在Android版本中,标题栏的空间是没有减少的状态栏,并让它成为其他版本相同。
因此,这里是我如何解决它。在清单,我不停的code,因为它是
安卓主题=@安卓风格/ Theme.Light.NoTitleBar
删除标题栏的应用
和其中使用我查了Android版本定制的线性布局,并保持到姜饼小于等于版本的应用程序全屏的活动。
如果(Build.VERSION.SDK_INT< = Build.VERSION_ codeS.GINGERBREAD)
{
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow()。setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}I am have a facebook like sliding menu bar in my app in which the two content and main layout of the app is handled by a Custom layout class.
I want to remove the titlebar of my app
Issue:
Even though I place
android:Theme.Light.NoTitleBar
in my manifest there is a blank space of title bar. Due to which my whole layout is pushed downwards.
I have tried using
requestWindowFeature(Window.FEATURE_NO_TITLE);
and
getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
but still the titlebar space is not removed.
This is how the app looks like
I think this is caused due to the Custom LinearLayout class which holds the main sliding layout. But I am unable to remove the titlebar space from the custom layout class. Suggest a better solution.
Custom Layout Class
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); } }
解决方案Finally I was able to remove the titlebar space. As it turns out, including this tag
android:theme="@android:style/Theme.Light.NoTitleBar.Fullscreen"
on application in manifest made the app fullscreen and corrected the issue. But I wanted the status bar to be visible in my app. So I had to compromise the status bar on the android versions in which the titlebar space was not reduced and let it be same on other versions. So here is how I resolved it.
in Manifest, I kept the code as it is
android:theme="@android:style/Theme.Light.NoTitleBar"
to remove the titlebar in the app
and in the activity which used the custom linear layout I checked the android version and kept the app fullscreen on versions less than and equal to Gingerbread.
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD) { requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); }
这篇关于Android的Theme.NoTitleBar不列入工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!