BottomNavigationView пусто - PullRequest
       8

BottomNavigationView пусто

0 голосов
/ 09 марта 2020

Я следовал этому уроку для добавления BottomNavigationView в мой проект Android Studio.

Я перенес свой проект в AndroidX и заметил BottomNavigationView, который он использует в видео может быть несовместимо с AndroidX, поэтому я решил использовать implementation 'com.google.android.material:material:1.1.0'.

Проблема

После добавления BottomNavigationView и настройки всех соответствующих атрибутов, я вижу, что он все еще пустой, несмотря на то, что он выполняет все инструкции и проверяет, все ли правильно.

Обратите внимание, что BottomNavigationView полностью пуст и имеет высоту 0

Это XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools">

    <FrameLayout
        android:id="@+id/frameLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@id/frameLayout"/>

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        app:menu="@menu/bottom_navigation"/>
</RelativeLayout>

моей деятельности, а это пункты моего меню XML

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <item
        android:id="@+id/homeButton"
        android:icon="@android:drawable/ic_menu_agenda"
        android:title="a funny item"/>
    <item
        android:id="@+id/favoritesButton"
        android:icon="@android:drawable/ic_menu_info_details"
        android:title="favorites"/>
    <item
        android:id="@+id/ideaButton"
        android:icon="@android:drawable/ic_menu_agenda"
        android:title="ideas"/>
</menu>

Что здесь не так? Чего мне не хватает?

1 Ответ

2 голосов
/ 09 марта 2020

enter image description here

добавить в свои зависимости

implementation 'com.google.android.material:material:1.2.0-alpha03'

стиль. xml

<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

активность. xml

<?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"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <FrameLayout
        android:id="@+id/frameLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@id/frameLayout"
        app:layout_constraintBottom_toTopOf="@+id/bottomNavigationView"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/bottomNavigationView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:menu="@menu/bottom_navigation" />

</androidx.constraintlayout.widget.ConstraintLayout>

меню xml файл

<?xml version="1.0" encoding="utf-8"?>
    <menu xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto">
        <item
            android:id="@+id/homeButton"
            android:icon="@android:drawable/ic_menu_agenda"
            android:title="a funny item"/>
        <item
            android:id="@+id/favoritesButton"
            android:icon="@android:drawable/ic_menu_info_details"
            android:title="favorites"/>
        <item
            android:id="@+id/ideaButton"
            android:icon="@android:drawable/ic_menu_agenda"
            android:title="ideas"/>
    </menu>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...