【问题标题】:Navigation and status bar in androidandroid中的导航和状态栏
【发布时间】:2021-05-05 11:14:26
【问题描述】:

我试图隐藏和显示控制器、导航和点击状态。问题是我无法隐藏底部的空白。另一件事是我不知道如何在隐藏时显示导航和状态栏。

if (!actionBar.isShowing()) {
  actionBar.show();
  playerView.showController();

 } else {

     getWindow().getDecorView().setSystemUiVisibility(
     View.SYSTEM_UI_FLAG_IMMERSIVE
     // Set the content to appear under the system bars so that the
     // content doesn't resize when the system bars hide and show.
     | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
     | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
     | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
     // Hide the nav bar and status bar
     | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
     | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
     | View.SYSTEM_UI_FLAG_FULLSCREEN);
     actionBar.hide();
     playerView.hideController();
 }

这是布局文件

这是布局文件

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:animateLayoutChanges="true"
    android:fitsSystemWindows="true"
    android:id="@+id/activity_player_layout"
    >
    <androidx.appcompat.widget.Toolbar
        android:layout_width="match_parent"
        android:elevation="4dp"
        app:titleTextColor="@color/white"
        android:layout_height="?attr/actionBarSize"
        />

   <com.google.android.exoplayer2.ui.PlayerView
      android:id="@+id/exoplayer_video"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:background="@color/black"
      app:bar_height="4dp"
      app:controller_layout_id="@layout/custom_controller"
      app:player_layout_id="@layout/exo_simple_player_view"
      app:resize_mode="fit"
      app:shutter_background_color="@color/black"
      app:use_controller="true"
      app:use_sensor_rotation="true">

      </com.google.android.exoplayer2.ui.PlayerView>

</RelativeLayout>

【问题讨论】:

    标签: android show-hide statusbar navigationbar


    【解决方案1】:

    您需要为主布局设置点击监听,但使用相对布局作为主布局,因为我认为相对布局会起作用

    layout.setOnClickListener(new View.OnClickListener() {
    
        boolean show = true;
    
        @Override
        public void onClick(View v) {
            Toast.makeText(MainActivity.this, "CLICK", Toast.LENGTH_SHORT).show();
            if (show) {
                  toolbar.animate().translationY(-toolbar.getBottom()).setInterpolator(new AccelerateInterpolator()).start();
                hideSystemUI();
                show = false;
            } else {
                toolbar.animate().translationY(0).setInterpolator(new DecelerateInterpolator()).start();
                  showSystemUI();
                  show = true;
         }
     }
    });
    
    
    private void hideSystemUI() {
        // Set the IMMERSIVE flag.
        // Set the content to appear under the system bars so that the content
        View decorView = getWindow().getDecorView();
        decorView.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);
    
    }
    
    private void showSystemUI() {
        View decorView = getWindow().getDecorView();
        decorView.setSystemUiVisibility(
                View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                        | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                        | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
    
    
    }
    

    【讨论】:

    • 我试过了,结果还是一样。
    • 结果如何?显示您的布局 + 代码
    • 导航栏存在的底部有空白。我已经测试了您的代码,因为它在我的设备中。其他一切正常。
    • 我想看看你的布局
    • 我已经添加了上面的布局。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-29
    • 2022-08-05
    • 2016-02-02
    • 1970-01-01
    相关资源
    最近更新 更多