如何隐藏操作栏并将 videoview 设置为全屏

how to hide the actionbar and make the videoview set to full screen

我正在尝试制作视频播放器。我的问题是当方向改变时,videoView 不适合整个屏幕并且我的操作栏没有隐藏...

这是我的代码。

RowClick.java

public class RowClick extends AppCompatActivity {
VideoView videoView;
MediaController mediaController;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
        OrientationEventListener orientationEventListener = new OrientationEventListener(this) {
            @Override
            public void onOrientationChanged(int orientation) {
                if (orientation == Configuration.ORIENTATION_PORTRAIT) {
                    getSupportActionBar().show();
                } else if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
                    getSupportActionBar().hide();
                }
            }
        };

        if (orientationEventListener.canDetectOrientation()) {
            orientationEventListener.enable();
        }

        setContentView(R.layout.activity_row_click);
        videoView = findViewById(R.id.video);
        mediaController = new MediaController(this);
        StorageReference storageReference = FirebaseStorage.getInstance().getReference().child("video/-L8Vf_Xa6PBhyqbEzlif");
        storageReference.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
            @Override
            public void onSuccess(Uri uri) {
                videoView.setVideoURI(uri);
                videoView.requestFocus();

            }
        });

        mediaController.setAnchorView(videoView);
        videoView.setMediaController(mediaController);
        videoView.start();
    }
}

activity_row_click.xml

<?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:id="@+id/layout"
    tools:context="com.mgb.sdakaraoke.RowClick">

    <VideoView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/video"
        />

</RelativeLayout>

AndroidManifest.xml

 <activity
            android:name=".RowClick"
            android:configChanges="orientation|screenSize">
        </activity>

我的目标是当方向等于横向时必须隐藏操作栏并且videoview必须设置为全屏。

请帮助我实现该目标。

下面是横屏模式的截图,需要根据我的目标正确更改。

在清单中,您将在 activity 标签下有这样的东西:

android:theme="@style/AppTheme.NoActionBar"

这将删除操作栏。 至于横向全屏,请在此处尝试:answer from other user

将此添加到您的 styles.xml

<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="android:windowTranslucentStatus">true</item>
</style>

将其应用于清单中的 activity:

<activity
        android:name=".RowClick"
        android:theme="@style/AppTheme.NoActionBar"
        android:configChanges="orientation|screenSize">
</activity>

这也会使您的状态栏变透明。

您也可以在 java 文件代码中尝试以下操作。

@Override
public void onConfigurationChanged(Configuration newConfig) {
 super.onConfigurationChanged(newConfig);
 if(newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
      getActionBar().hide();
 } else {
      getActionBar().show();
 }
}

if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
  getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
else {
  getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
}