Я пытаюсь использовать навигационный блок навигации и нижнюю панель в своем приложении. Поэтому сначала я создал навигационную активность. Затем я попытался добавить навигацию нижней панели к той же операции. Я хочу развиваться как это приложение:
без BottomNavigationView в Activity.xml приложение работает. Но когда я добавляю BottomNavigationView в Activity.xml, приложение не работает. Ничего не отображается в logcat. Как я могу использовать навигацию и навигационную панель Bottombar в одном упражнении, приведите простой пример? Спасибо
Добавьте родителя в <include..../>
затем добавьте BottomNavigationView
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<include
layout="@layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.BottomNavigationView
android:id="@+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@color/colorPrimary"
app:itemTextColor="@color/colorAccent"
app:menu="@menu/bottom_navigation_menu"/>
</RelativeLayout>
Используйте TabLayout вместо нижней навигации TabLayout лучше и проще
создать root.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:id="@+id/drawerlayout"
android:layout_height="match_parent">
<include layout="@layout/activity_main"/>
<include layout="@layout/navi_drawer"/>
</android.support.v4.widget.DrawerLayout>
создать navi_drawer
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="280dp"
android:layout_height="match_parent"
android:layout_gravity="right"
android:background="?attr/navigationBackground"
android:orientation="vertical">
</LinearLayout>
и activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/backgroundActivity"
android:orientation="vertical">
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
</android.support.v4.view.ViewPager>
<LinearLayout
android:id="@+id/lnrTab"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layoutDirection="rtl"
android:orientation="vertical"
app:layout_anchor="@+id/viewpager"
app:layout_anchorGravity="bottom|center">
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/dividers_color_dark"
app:layout_anchor="@+id/viewpager"
app:layout_anchorGravity="bottom|center" />
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="false"
app:tabBackground="?attr/backgroundTab"
app:tabContentStart="9dp"
app:tabGravity="fill"
app:tabIndicatorColor="@color/colorAccent"
app:tabIndicatorHeight="1dp"
app:tabMode="scrollable" />
</LinearLayout>
</LinearLayout>
затем MainActivity
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.root);
//config your TabLayout
}