android java禁用触摸屏主页按钮

时间:2017-06-02 09:34:49

标签: java android android-theme

我在第一次运行时使用滑块创建应用程序,但似乎,android主页按钮覆盖了我的布局。 enter image description here

我怎么能隐藏触摸屏主页按钮?

感谢

我尝试使用此代码但无法正常工作:

 getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);

我尝试使用填充底部,但它在设备上显示一些不使用触摸屏主页按钮的空间。

任何人体验过这个?

4 个答案:

答案 0 :(得分:0)

使用以下代码隐藏导航栏

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
              | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
              | View.SYSTEM_UI_FLAG_FULLSCREEN
              | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
decorView.setSystemUiVisibility(uiOptions);

Source

答案 1 :(得分:0)

试试此代码:Android沉浸式模式将完美无缺。

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 // hide nav bar
            | View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
            | View.SYSTEM_UI_FLAG_IMMERSIVE);

immersive mode android click here

答案 2 :(得分:0)

试试这个,

public static int getSoftButtonsBarSizePort(Activity activity) {
        // getRealMetrics is only available with API 17 and +
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            DisplayMetrics metrics = new DisplayMetrics();
            activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
            int usableHeight = metrics.heightPixels;
            activity.getWindowManager().getDefaultDisplay().getRealMetrics(metrics);
            int realHeight = metrics.heightPixels;
            if (realHeight > usableHeight)
                return ((realHeight - (usableHeight)) / 4);
            else
                return 0;
        }
        return 0;
    }

并且在创建时,你必须

RelativeLayout.LayoutParams relativeParams = (RelativeLayout.LayoutParams) layout2.getLayoutParams();
    relativeParams.setMargins(0, 0, 0, getSoftButtonsBarSizePort(DimgloActivity.this));  // left, top, right, bottom
    layout2.setLayoutParams(relativeParams);

答案 3 :(得分:0)

在设置视图之前,在onCreate中调用此方法: -

    Constants.fullScreen(this); //call before setting view
    setContentView(R.layout.activity_generator);
    final_tv = (TextView) findViewById(R.id.final_tv);
    .
    .

在Constant中创建此函数,您可以根据需要注释或删除某些行

public static void fullScreen(Activity activity) 
{
   activity.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_STICKY);
}
相关问题