【问题标题】:how to make swipeable Bottom Navigation View in android studio with java?如何使用java在android studio中制作可滑动的底部导航视图?
【发布时间】:2021-05-15 12:15:13
【问题描述】:

我在底部有底部导航视图,我想让它可以滑动。有什么方法可以让它们滑动吗? 这是它的外观

这里是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);

    }
}

【问题讨论】:

    标签: java android android-studio navigationbar bottomnavigationview


    【解决方案1】:

    你可以使用沉浸式模式,查看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);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-29
      • 1970-01-01
      • 2020-01-12
      • 1970-01-01
      相关资源
      最近更新 更多