You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在承载ExoPlayer的Activity中显示Android顶部及底部导航栏?

问题分析与解决方案

这是因为SimpleExoPlayerView的默认控制器会自动触发沉浸式全屏模式:当它处于可见状态时,会自动隐藏系统状态栏和底部导航栏;而你把它设为invisible时,这个触发逻辑不会执行,导航栏就恢复正常显示了。

下面给你几个可行的解决方法:

方法一:通过XML配置禁用自动隐藏行为

首先在根布局LinearLayout中添加app命名空间:

<LinearLayout 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:orientation="vertical"
    tools:context="com.srushti.holmes.clipPlayActivity">

然后给SimpleExoPlayerView添加属性,禁用控制器自动隐藏和触摸隐藏的逻辑:

<com.google.android.exoplayer2.ui.SimpleExoPlayerView
    android:id="@+id/exoplayer"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    app:controller_auto_show="false"
    app:controller_hide_on_touch="false" />

方法二:通过代码强制保留系统UI

如果需要保留控制器的自动显示/隐藏功能,但不想让导航栏消失,可以在Activity的onCreate方法中添加逻辑,覆盖ExoPlayer的系统UI设置:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.your_activity_layout);
    
    // 强制显示状态栏和导航栏
    getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
    // 清除全屏标记,防止窗口进入全屏模式
    getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
    
    // 初始化ExoPlayer
    SimpleExoPlayerView exoPlayerView = findViewById(R.id.exoplayer);
    // 监听控制器可见性变化,确保系统UI始终显示
    exoPlayerView.setControllerVisibilityListener(new PlayerControlView.VisibilityListener() {
        @Override
        public void onVisibilityChange(int visibility) {
            getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
        }
    });
    
    // 后续的ExoPlayer初始化逻辑...
}

方法三:自定义ExoPlayer控制器(进阶)

如果上面的方法都不符合需求,你可以完全自定义ExoPlayer的控制器布局,彻底掌控UI行为,避免默认的沉浸式触发。只需给SimpleExoPlayerView设置自定义控制器布局:

<com.google.android.exoplayer2.ui.SimpleExoPlayerView
    android:id="@+id/exoplayer"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    app:controller_layout_id="@layout/your_custom_controller" />

之后自己实现控制器的布局和交互逻辑即可。

内容的提问来源于stack exchange,提问作者Pavan G R

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 07:16:40