显示和隐藏导航栏和动作条的OnClick |安卓 [英] Display and Hide NavigationBar and ActionBar OnClick|Android

查看:251
本文介绍了显示和隐藏导航栏和动作条的OnClick |安卓的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想隐藏和显示操作栏,并在屏幕上点击导航栏中的(我不关心那里的屏幕上)和2秒后隐藏起来。

我看,我可以用这                   处理程序H =新的处理程序();

  h.postDelayed(新的Runnable(){

                @覆盖
                公共无效的run(){
                //执行延迟STUFF
                   getActionBar()隐藏()。
                 }
                 }, 延迟时间);
 

但我的问题是关于点击任何反应。

另外一个问题,我想该屏幕不走黑中没有活性。

修改


我想这

 公共无效onUserInteraction(){
    // TODO自动生成方法存根

    super.onUserInteraction();
    getActionBar()显示()。
    新的处理程序()。postDelayed(新的Runnable(){

        @覆盖
        公共无效的run(){

            getActionBar()隐藏()。

        }
    },1000);
}
 

但是当我触碰屏幕中显示的状态栏。只有在秒触摸动作条显示。 1秒,但状态栏和导航栏的逗留后,操作栏去。 我不希望这样的状态栏,也希望我的导航栏隐藏在动作条隐藏。

**我添加了全屏FLAG在Oncreat artivity。 谢谢

EDIT2


 公共无效fullScreenLandSpace(){
    //这个功能配置全屏和解构只有!
    getActionBar()setDisplayShowTitleEnabled(假)。
    getActionBar()setDisplayShowHomeEnabled(假)。
    查看decorView = getWindow()getDecorView()。
    INT uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
    decorView.setSystemUiVisibility(uiOptions);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    getActionBar()隐藏()。

}
@覆盖
公共无效onUserInteraction(){
    // TODO自动生成方法存根

    super.onUserInteraction();
    getActionBar()显示()。
    。getWindow()getDecorView()setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN)。
    新的处理程序()。postDelayed(新的Runnable(){

        @覆盖
        公共无效的run(){

            getActionBar()隐藏()。
             getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION|View.SYSTEM_UI_FLAG_FULLSCREEN);

        }
    },1000);
}
 

解决方案

  @覆盖
    公共无效onUserInteraction(){
        // TODO自动生成方法存根
        super.onUserInteraction();
        新的处理程序()。postDelayed(新的Runnable(){

            @覆盖
            公共无效的run(){
                // TODO自动生成方法存根
                查看decorView = getWindow()getDecorView()。
                //隐藏状态栏。
                INT uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                        ;
                decorView.setSystemUiVisibility(uiOptions);
                //记住,你永远不应该显示操作栏,如果
                //状态栏是隐藏的,所以隐藏太多,​​如果有必要的。
                动作条动作条= getActionBar();
                actionBar.hide();
            }
        },1000);
    }
 

// --------------------------------------------- ------ //添加以下code

 查看decorView = getWindow()getDecorView()。
//隐藏状态栏。
INT uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
//记住,你永远不应该显示操作栏,如果
//状态栏是隐藏的,所以隐藏太多,​​如果有必要的。
动作条动作条= getActionBar();
actionBar.hide();
 

// -------------------------------

 查看decorView = getWindow()getDecorView()。
//隐藏无论是导航栏和状态栏。
// SYSTEM_UI_FLAG_FULLSCREEN仅在Android 4.1及更高版本,但作为
//一般情况下,你应该设计自己的应用程序来隐藏状态栏时,你
//隐藏导航栏。
INT uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
              | View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
 

I want to hide and show the action bar and the navigation bar on click on the screen (I dont care where on the screen) and hide them after 2 sec.

I read that I can use this Handler h = new Handler();

               h.postDelayed(new Runnable() {

                @Override
                public void run() {
                // DO DELAYED STUFF
                   getActionBar().hide();
                 }
                 }, delaytime);

but My problem that on click nothing is happened.

another question I want The screen does not go black in no activity.

EDIT


I tried this

public void onUserInteraction() {
    // TODO Auto-generated method stub

    super.onUserInteraction();
    getActionBar().show();
    new Handler().postDelayed(new Runnable() {

        @Override
        public void run() {

            getActionBar().hide();

        }
    }, 1000);
}

but when I touch the screen the status bar shown. and only in sec touch the actionbar shows. The action bar goes after 1 sec but the status bar and navigation bar stay. I dont want that the status bar and also I want that the navigation bar hide when the actionbar hides.

** I add the FULL SCREEN FLAG at the Oncreat artivity. Thanks

EDIT2


public void fullScreenLandSpace(){
    //This function configure FullScreen and LandSpace Only!
    getActionBar().setDisplayShowTitleEnabled(false);
    getActionBar().setDisplayShowHomeEnabled(false);
    View decorView = getWindow().getDecorView();
    int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN|View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
    decorView.setSystemUiVisibility(uiOptions);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    getActionBar().hide();

}
@Override
public void onUserInteraction() {
    // TODO Auto-generated method stub

    super.onUserInteraction();
    getActionBar().show();
    getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN);
    new Handler().postDelayed(new Runnable() {

        @Override
        public void run() {

            getActionBar().hide();
             getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION|View.SYSTEM_UI_FLAG_FULLSCREEN);

        }
    }, 1000);
}

解决方案

   @Override
    public void onUserInteraction() {
        // TODO Auto-generated method stub
        super.onUserInteraction();
        new Handler().postDelayed(new Runnable() {

            @Override
            public void run() {
                // TODO Auto-generated method stub
                View decorView = getWindow().getDecorView();
                // Hide the status bar.
                int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN|View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                        ;
                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();
            }
        }, 1000);
    }

//--------------------------------------------------- //add following code

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();

//-------------------------------

View decorView = getWindow().getDecorView();
// Hide both the navigation bar and the status bar.
// SYSTEM_UI_FLAG_FULLSCREEN is only available on Android 4.1 and higher, but as
// a general rule, you should design your app to hide the status bar whenever you
// hide the navigation bar.
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
              | View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);

这篇关于显示和隐藏导航栏和动作条的OnClick |安卓的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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