Как так сделать в Android Studio? Bottom navigation + FAB?
Всем привет! Никак не могу допетрить, уже 3 сутки сижу, читаю документацию, читаю вики на material io от Google, но никак не могу реализовать задуманное! Необходимо нижнюю навигацию сделать как на 1 фото, но получается максимум как на 2 фото... Я так понимаю это Bottom navigation + FAB, но ни в какую не реализуется, не знаю каким образом уже что делать...
activity_main:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="?attr/actionBarSize"
tools:context=".MainActivity">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/nav_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="0dp"
android:layout_marginEnd="0dp"
android:background="?android:attr/windowBackground"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="@menu/bottom_nav_menu" />
<fragment
android:id="@+id/nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:defaultNavHost="true"
app:layout_constraintBottom_toTopOf="@id/nav_view"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:navGraph="@navigation/mobile_navigation" />
</androidx.constraintlayout.widget.ConstraintLayout>
bottom_nav_menu:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/navigation_home"
android:icon="@drawable/ic_home_black_24dp"
android:title="История" />
<item
android:id="@+id/navigation_dashboard"
android:icon="@drawable/ic_add_circle_black_24dp"
android:title="Отчеты" />
<item
android:id="@+id/navigation_notifications"
android:icon="@drawable/ic_notifications_black_24dp"
android:title="Напоминания" />
<item
android:id="@+id/navigation_other"
android:icon="@drawable/ic_notifications_black_24dp"
android:title="Больше" />
Ответы (1 шт):
Автор решения: Cypher
→ Ссылка
Вот рабочий пример с моего проекта. Подгоните под себя.
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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/detail_background"
tools:context=".view.activity.DetailActivity">
<com.airbnb.lottie.LottieAnimationView
android:id="@+id/unstar_anim"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginTop="50dp"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:lottie_fileName="unstar.json"
tools:visibility="visible" />
<com.airbnb.lottie.LottieAnimationView
android:id="@+id/star_anim"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginTop="50dp"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:lottie_fileName="star.json"
tools:visibility="visible" />
<com.airbnb.lottie.LottieAnimationView
android:id="@+id/progress_anim"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_marginTop="50dp"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:lottie_fileName="detail_progress.json"
tools:visibility="visible" />
<ImageView
android:id="@+id/image"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="50dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:src="@drawable/mclaren" />
<TextView
android:id="@+id/similar_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginBottom="40dp"
android:fontFamily="cursive"
android:text="@string/similar_images"
android:textColor="@color/colorDetailPrimary"
android:textSize="18sp"
app:layout_constraintBottom_toTopOf="@+id/similar_progress"
app:layout_constraintStart_toStartOf="parent" />
<com.airbnb.lottie.LottieAnimationView
android:id="@+id/similar_progress"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="@+id/similar_recycler"
app:layout_constraintEnd_toEndOf="@id/similar_recycler"
app:layout_constraintStart_toStartOf="@id/similar_recycler"
app:layout_constraintTop_toTopOf="@+id/similar_recycler"
app:lottie_fileName="detail_progress.json" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/similar_recycler"
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_marginBottom="85dp"
android:orientation="horizontal"
android:overScrollMode="never"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
tools:itemCount="6"
tools:listitem="@layout/item_similar" />
<com.airbnb.lottie.LottieAnimationView
android:id="@+id/swipe_anim"
android:layout_width="100dp"
android:layout_height="100dp"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:lottie_fileName="swipe.json"
tools:visibility="visible" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab_full"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="12dp"
android:background="?android:attr/selectableItemBackground"
android:elevation="8dp"
android:visibility="gone"
app:layout_constraintBottom_toTopOf="@+id/fab_set_wall"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:srcCompat="@drawable/ic_fullscreen"
tools:visibility="visible" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab_set_wall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="100dp"
android:background="?android:attr/selectableItemBackground"
android:elevation="8dp"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:srcCompat="@drawable/ic_wallpaper"
tools:visibility="visible" />
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="@+id/bottom_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_add"
app:layout_anchor="@id/bottom_app_bar" />
<com.google.android.material.bottomappbar.BottomAppBar
android:id="@+id/bottom_app_bar"
style="@style/Widget.MaterialComponents.BottomAppBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:backgroundTint="@color/colorPrimaryDark"
app:fabAlignmentMode="center"
app:menu="@menu/menu_detail"
app:navigationIcon="@drawable/ic_arrow_back" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
Есть подробный туториал как это делать: https://devcolibri.com/implementing-bottomappbar-material-components-for-android-part-1/