在安卓4.4+隐藏状态栏或奇巧与全屏 [英] Hide status bar in android 4.4+ or kitkat with Fullscreen

查看:838
本文介绍了在安卓4.4+隐藏状态栏或奇巧与全屏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用下面code为隐藏状态栏全屏目的:

I'm using following code for hiding status bar with full screen purpose:

    void HideEverything(){
        if (Build.VERSION.SDK_INT < 16) {
            getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                    WindowManager.LayoutParams.FLAG_FULLSCREEN);
        } else {
            View decorView = getWindow().getDecorView();
            // Hide the status bar.
            int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
            decorView.setSystemUiVisibility(uiOptions);
            // Remember that you should never show the action bar if the
            // status bar is hidden, so hide that too if necessary.
            ActionBar actionBar = getActionBar();
            actionBar.hide();
        }
    }

这显示了在全屏模式下的屏幕,但是当我触摸状态栏中它显示状态栏。
我试过其他选项来添加全屏,并在清单中的应用程序和活动水平没有标题栏的主题,但还是结果都是一样的...:(

It shows Screen in full-screen mode but when I touch status bar it shows status bar. I tried other options to add the full screen and no title bar theme in application and activity level in manifest, but still results are the same... :(

我不希望显示在任何步骤状态栏。
如何在Android中实现这一目标?

I don't want to show status bar at any step. How to achieve this in android?

编辑:

Android操作系统版本4.4.2是
(以上code正在4.3,但不是4.4.2)

Android OS version is 4.4.2 (Above code is working on 4.3 but not on 4.4.2)

更新:

问题得以解决...
答案已写在下面单独...

Problem is solved... Answer is written below separately...

推荐答案

没有解决办法的问题,因为Android版本的工作是4.4.2。

No solution could work on the problem as Android version is 4.4.2.

但按照建议由阳光,问题是由preventing状态栏的扩展解决了。

But as per the suggestion by Sunny, problem is solved by preventing the expansion of status bar.

解决办法是:

写一个内联 customViewGroup 类在您的主要活动。

Write an inline customViewGroup class in your main activity.

public class customViewGroup extends ViewGroup {

        public customViewGroup(Context context) {
            super(context);
        }

        @Override
        protected void onLayout(boolean changed, int l, int t, int r, int b) {
        }

        @Override
        public boolean onInterceptTouchEvent(MotionEvent ev) {
            Log.v("customViewGroup", "**********Intercepted");
            return true;
        }
    }

现在在 mainActivity 你的的onCreate 方法中添加以下之前的setContentView code ()

Now in your onCreate method of mainActivity add following code before setContentView() :

WindowManager manager = ((WindowManager) getApplicationContext()
                .getSystemService(Context.WINDOW_SERVICE));

        WindowManager.LayoutParams localLayoutParams = new WindowManager.LayoutParams();
        localLayoutParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
        localLayoutParams.gravity = Gravity.TOP;
        localLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|

                // this is to enable the notification to recieve touch events
                WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |

                // Draws over status bar
                WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;

        localLayoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
        localLayoutParams.height = (int) (50 * getResources()
                .getDisplayMetrics().scaledDensity);
        localLayoutParams.format = PixelFormat.TRANSPARENT;

        customViewGroup view = new customViewGroup(this);

        manager.addView(view, localLayoutParams);

以上code将禁用状态栏的扩张。
现在做一个全屏按照code,添加它仅低于上述code和之前的的setContentView

//fullscreen
        requestWindowFeature(Window.FEATURE_NO_TITLE);   
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);

现在清单中添加的权限:

Now in manifest add the permission:

<!-- prevent expanding status bar -->
    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>

和你做....:)

缺点::此code 禁用状态栏的扩张设备不只是一个活动或应用程序,所以使用它,如果你真的需要它。

drawback : This code disables expansion of status bar for the device not just for an activity or an application, so use it if you really need it.

感谢您​​所有的解决方案和建议...:)

这篇关于在安卓4.4+隐藏状态栏或奇巧与全屏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆