【发布时间】:2018-04-15 19:32:14
【问题描述】:
我使用的是BottomNavigationViewEX,每次单击此栏的一个按钮时,整个页面都在加载,甚至底部和顶部栏。
这是我在每个活动中使用的代码:
private void setupBottomNavigationView() {
Log.d(TAG, "setupBottomNavigationView: setting up BottomNavigationView");
BottomNavigationViewEx bottomNavigationViewEx = (BottomNavigationViewEx) findViewById(R.id.BottomNavViewBar);
BottomNavigationViewHelper.setupBottomNavigationView(bottomNavigationViewEx);
BottomNavigationViewHelper.enableNavigation(HomeActivity.this, bottomNavigationViewEx);
Menu menu = bottomNavigationViewEx.getMenu();
MenuItem menuItem = menu.getItem(ACTIVITY_NUM);
menuItem.setChecked(true);
}
我很确定我应该只在一个活动中设置我的底部栏,而不是每个活动,但我是 Android Studio 的初学者,所以我不确定如何实现。
感谢您的帮助,我会根据需要提供尽可能多的信息。
编辑 1:这里是 activity_popcore.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
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"
tools:context=".popcore">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Top Bar -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/relLayout1">
<include layout="@layout/layout_top_tabs"/>
</RelativeLayout>
<!-- Body -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/relLayout2"
android:layout_below="@+id/relLayout1">
<include layout="@layout/layout_center_viewpager"/>
</RelativeLayout>
<!-- Bottom Bar -->
<include layout="@layout/layout_bottom_navigation_view"/>
</RelativeLayout>
这是我的 layout_bottom_navigation_view.xml :
<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true">
<com.ittianyu.bottomnavigationviewex.BottomNavigationViewEx
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/BottomNavViewBar"
android:background="@drawable/dark_grey_border_top"
app:itemIconTint="@color/bottom_nav_item_colors"
app:itemTextColor="@color/bottom_nav_item_colors"
app:menu="@menu/bottom_navigation_menu">
</com.ittianyu.bottomnavigationviewex.BottomNavigationViewEx>
</RelativeLayout>
如果您需要更多信息,请联系我,感谢您的帮助!
【问题讨论】:
标签: android android-layout android-studio bottomnavigationview