【问题标题】:How to avoid navigation bar overlay on the video seekbar如何避免视频搜索栏上的导航栏覆盖
【发布时间】:2015-09-01 11:45:25
【问题描述】:

我有一个视频活动,顶部带有标题,SeekBar 底部带有媒体控件。当触发触摸事件时,标题和SeekBar 布局都会覆盖在SurfaceView 上,并且它们会在一定时间后消失。我还实现了沉浸式模式,其中状态栏和导航栏与标题和SeekBar 一起消失。我已经设法使用以下属性为状态栏腾出空间,而不会覆盖在标题布局上。

android:fitsSystemWindows="true"

但是,如果我对屏幕底部的媒体控件布局使用相同的属性,它就不起作用。结果,导航栏覆盖在布局上。我不明白为什么上述属性在一种布局上运行良好,而在另一种布局上运行良好。我有一个自定义的媒体控件布局,我有一个扩展FrameLayout 的类。 fitSystemWindows 属性是否不适用于自定义布局?请参阅第一个屏幕截图中右下角的图标。如第二个屏幕截图所示,它被导航栏覆盖

我在下面包含了我的部分类文件和布局。

MediaController.java

public class MediaController extends FrameLayout {

    //Some private fields are declared here

    public MediaController(Context context, boolean useFastForward, boolean useFullScreenButton) {
        super(context);
        ....
    }

    public MediaController(Context context) {
        this(context, true, false);
    }

    @Override
    public void onFinishInflate() {
        if (mRoot != null)
            initControllerView(mRoot);
    }

    //Inflating the layout here
    protected View makeControllerView() {
        LayoutInflater inflate = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        mRoot = inflate.inflate(R.layout.media_controller, null);
        ....
        return mRoot;
    }

    //Lot of other methods here

}

media_controller.xml

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:fitsSystemWindows="true"> <!--Using the attribute here-->

    <ImageButton android:id="@+id/pause"
        android:layout_gravity="top"
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:background="@android:color/transparent"/>

    <TextView android:id="@+id/time_current"
        android:layout_gravity="center_horizontal"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="@color/white"/>

    <SeekBar
        android:id="@+id/mediacontroller_progress"
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="0dip"
        android:layout_weight="1"
        android:layout_height="32dip" />

    <TextView android:id="@+id/time"
        android:layout_gravity="center_horizontal"
        android:textColor="@color/white"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

    <ImageButton android:id="@+id/fullscreen"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@android:color/transparent"
        android:contentDescription="@string/description" />

</LinearLayout>

【问题讨论】:

  • 我强烈建议您分享一个简短的视频(或屏幕截图)来解决问题,然后解释它应该如何工作。
  • @Nactus 我已经添加了截图。谢谢。
  • “请参阅第一个屏幕截图中右下角的图标。它被导航栏覆盖,如第二个屏幕截图所示”,所以如果我理解正确,您会喜欢在媒体播放器处于活动状态时隐藏导航栏,对吗? (第一张图是它的样子,第二张图是你得到的,对吗?)
  • 我可以隐藏它,但是当我触摸屏幕时,我会看到你在第二张图片中看到的内容。我唯一不想要的是将导航栏覆盖在右下角的图标上。图标应向导航栏左侧移动。

标签: android seekbar navigationbar android-fullscreen


【解决方案1】:

如果你不需要导航栏,像这样隐藏它:

// onResume ensures that every time the application is resumed, the nav bar goes away
    @TargetApi(Build.VERSION_CODES.HONEYCOMB)
    @Override
    protected void onResume() {

        super.onResume();

        View decorView = getWindow().getDecorView();
        //int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
        int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
        decorView.setSystemUiVisibility(uiOptions);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
    }

另外,看看这个:

在 Android 4.1 及更高版本上,您可以将应用程序的内容设置为显示在导航栏后面,以便内容不会调整大小 随着导航栏的隐藏和显示。为此,请使用 SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION。您可能还需要使用 SYSTEM_UI_FLAG_LAYOUT_STABLE 帮助您的应用保持稳定 布局。

当您使用这种方法时,您有责任确保 您的应用程序 UI 的关键部分最终不会被覆盖 系统吧。有关此主题的更多讨论,请参阅隐藏 状态栏课程。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-05-06
    • 2022-01-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多