Показать / скрыть BottomNavigationView для указанного фрагмента c - PullRequest
0 голосов
/ 05 мая 2020

В моем приложении android я хочу, чтобы нижняя строка меню исчезла, когда пользователь фокусирует SearchView (это также вызывает всплывающую экранную клавиатуру). Когда SearchView теряет фокус, я хочу снова показать нижнюю панель навигации.

Я пробовал использовать setVisibility(), и вид скрывается или отображается, но по какой-то причине он всегда сохраняет свою высоту. код для моего BottomNavigationView:

<com.google.android.material.bottomnavigation.BottomNavigationView
    android:id="@+id/bottom_navigation"
    android:layout_width="match_parent"
    android:layout_height="60dp"
    app:menu="@menu/bottom_navigation_menu"
    app:elevation="80dp"
    app:labelVisibilityMode="labeled"
    app:itemTextColor="@color/bottom_nav_color"
    app:itemIconTint="@color/bottom_nav_color"
    android:background="?attr/backgroundColor">

Код, который обрабатывает скрытие / отображение панели навигации:

// Needed to close the SearchView when pressing back (instead of just losing focus)
mSearchView.setOnQueryTextFocusChangeListener(
    (v, hasFocus) -> {
        if (!hasFocus) {
            adapter.isSearchMode = false;
            bottomNavigationView.setVisibility(View.VISIBLE);
            searchMenuItem.collapseActionView();
            adapter.notifyDataSetChanged();
        } else {
            adapter.isSearchMode = true;
            bottomNavigationView.setVisibility(View.GONE);
            searchMenuItem.collapseActionView();
            adapter.notifyDataSetChanged();
        }
    });

BottomNavigationView удерживается LinearLayout следующим образом:

<LinearLayout
                android:id="@+id/footer"
                android:baselineAligned="false"
                android:layout_width="match_parent"
                android:layout_height="60dp"
                android:layout_alignParentBottom="true"
                android:orientation="vertical">

                <View
                    android:layout_width="match_parent"
                    android:layout_height="3dp"
                    android:background="@drawable/bottom_bar_top_shadow"/>

                <com.google.android.material.bottomnavigation.BottomNavigationView
                    android:id="@+id/bottom_navigation"
                    android:layout_width="match_parent"
                    android:layout_height="60dp"
                    app:menu="@menu/bottom_navigation_menu"
                    app:elevation="80dp"
                    app:labelVisibilityMode="labeled"
                    app:itemTextColor="@color/bottom_nav_color"
                    app:itemIconTint="@color/bottom_nav_color"
                    android:background="?attr/backgroundColor">

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="50dp"
                        android:orientation="horizontal"
                        android:layout_marginTop="6dp"
                        android:weightSum="5"
                        android:elevation="16dp">

                        <RelativeLayout
                            android:layout_width="0dp"
                            android:layout_height="match_parent"
                            android:layout_weight="1"
                            android:gravity="center|top">

                            <TextView
                                android:id="@+id/missed_calls"
                                style="@style/unread_count_font"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:background="@drawable/unread_message_count_bg"
                                android:layout_marginStart="20dp"
                                android:gravity="center"
                                android:visibility="gone"/>

                        </RelativeLayout>

                        <RelativeLayout
                            android:layout_width="0dp"
                            android:layout_height="match_parent"
                            android:layout_weight="1"
                            android:gravity="center|top">

                            <TextView
                                android:id="@+id/missed_chats"
                                style="@style/unread_count_font"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:background="@drawable/unread_message_count_bg"
                                android:layout_marginStart="20dp"
                                android:gravity="center"
                                android:visibility="gone"/>

                        </RelativeLayout>

                    </LinearLayout>

                </com.google.android.material.bottomnavigation.BottomNavigationView>


            </LinearLayout>

1 Ответ

0 голосов
/ 05 мая 2020

На вашей BottomNavigation используйте этот фрагмент кода:

setVisibility(View.GONE)

View.Gone = Нет пробела слева для просмотра.

...