[英]how to make swipeable Bottom Navigation View in android studio with java?
I have Bottom Navigation View at the bottom and i want to make it swipeable.我在底部有底部导航视图,我想让它可以滑动。 is there any way to make them swipeable?有什么方法可以让它们滑动吗? here is how it looks这是它的外观
here is xml file这是 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>
Here is menu file which contains all the menu bar items这是包含所有菜单栏项的菜单文件
<?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>
My Mainactivity.java file is default one我的 Mainactivity.java 文件是默认文件
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
You can use immersive mode, checkthis您可以使用沉浸式模式,请检查此
// 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);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.