在Android的奇巧使用新的拟真模式 [英] Using new IMMERSIVE mode in android kitkat

查看:144
本文介绍了在Android的奇巧使用新的拟真模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想打一个活动进入身临其境模式,并尽快隐藏顶部和BUTTOM系统吧,因为它开始。

在Android的开发者网站,他们说我应该用 setSystemUiVisibility(),提供 SYSTEM_UI_FLAG_IMMERSIVE SYSTEM_UI_FLAG_HIDE_NAVIGATION

我怎样才能做到这一点,在活动的的OnCreate()的方法?我觉得 setSystemUiVisibility 中没有提供的Activity类,它应该在视图中发生。有没有解决办法?

更新

确定根据doorstuck我加了以下几行,但我没有看到任何改变,导航栏和BUTTOM按钮仍然可见:

 公共类MainActivity延伸活动{

    @覆盖
    保护无效的onCreate(包savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.activity_main);

        如果(savedInstanceState == NULL){
        }
        。getWindow()getDecorView()setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION)。
        。getWindow()getDecorView()setSystemUiVisibility(View.SYSTEM_UI_FLAG_IMMERSIVE)。
    }

    //休息活动code
 

解决方案

获取装饰观点:

  getWindow()。getDecorView()。setSystemUiVisibility(...)
 

记住,参数是位标志。只有调用上面的方法一次:

  getWindow()。getDecorView()。setSystemUiVisibility(
          View.SYSTEM_UI_FLAG_LAYOUT_STABLE
        | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
        | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
        | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
        | View.SYSTEM_UI_FLAG_FULLSCREEN
        | View.SYSTEM_UI_FLAG_IMMERSIVE);
 

I want to make an activity to go into IMMERSIVE mode and hide top and buttom system bars as soon as it starts.

In developers site of android they say I should use setSystemUiVisibility() and provide SYSTEM_UI_FLAG_IMMERSIVE and SYSTEM_UI_FLAG_HIDE_NAVIGATION.

How can I do this in the OnCreate() method of the activity? I think the setSystemUiVisibility is not provided in the Activity class and it should happen in a view. Is there a workaround?

UPDATE

ok According to doorstuck I added the following lines but I dont see any changes, navigation bar and buttom buttons are still visible :

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        if (savedInstanceState == null) {
        }
        getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
        getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_IMMERSIVE);
    }

    //Rest of activity code

解决方案

Get the decor view:

getWindow().getDecorView().setSystemUiVisibility(...)

Remember that the arguments are bit flags. Only call the method above once:

getWindow().getDecorView().setSystemUiVisibility(
          View.SYSTEM_UI_FLAG_LAYOUT_STABLE
        | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
        | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
        | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
        | View.SYSTEM_UI_FLAG_FULLSCREEN
        | View.SYSTEM_UI_FLAG_IMMERSIVE);

这篇关于在Android的奇巧使用新的拟真模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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