如何使用 java 在 android studio 中制作可滑动的底部导航视图?

how to make swipeable Bottom Navigation View in android studio with java?

我在底部有底部导航视图,我想让它可以滑动。有什么办法可以使它们可滑动吗? 这是它的样子

这里是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:background="@color/maincolor"
    tools:context=".MainActivity">

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        app:menu="@menu/nav_items"
        app:itemIconTint="@color/color"
        android:background="@color/secondarycolor"
        app:itemRippleColor="@color/white"
        app:labelVisibilityMode="labeled"
        app:itemTextColor="@color/color"
        >


    </com.google.android.material.bottomnavigation.BottomNavigationView>


</RelativeLayout>

这是包含所有菜单栏项目的菜单文件

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:id="@+id/home_btn"
        android:icon="@drawable/ic_home"
        android:title="@string/home"
        />
    <item android:id="@+id/search_btn"
        android:icon="@drawable/ic_search"
        android:title="@string/search"
        />
    <item android:id="@+id/playlist_btn"
        android:icon="@drawable/ic_playlist"
        android:title="@string/playlists"
        />
    <item android:id="@+id/settings_btn"
        android:icon="@drawable/ic_settings"
        android:title="@string/settings"
        />

</menu>

我的Mainactivity.java文件是默认的

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

    }
}

可以使用沉浸模式,勾选this

 // This snippet hides the system bars.
private void hideSystemUI() {
    // Set the IMMERSIVE flag.
    // Set the content to appear under the system bars so that the content
    // doesn't resize when the system bars hide and show.
    mDecorView.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);
}

// This snippet shows the system bars. It does this by removing all the flags
// except for the ones that make the content appear under the system bars.
private void showSystemUI() {
    mDecorView.setSystemUiVisibility(
            View.SYSTEM_UI_FLAG_LAYOUT_STABLE
            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
}