Android : Bottom Menu Bar Hides the Recycler View - android

in my app i created a bootom menubar layout with floating button and i include that in my main activity and also i place a recycler view in my main activity
i just add 100 items to display in my recyclerview to check whether it was working or not for that when i run my application the recycler view of last item hides inside the bottom menu bar how to solve this
here is the sample image of what i said
activity_main.xml
<include
layout="#layout/toolbar"
android:id="#+id/toolbar"
/>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recycle"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/toolbar"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
/>
<include
android:id="#+id/bottom_nav"
layout="#layout/bottom_menu_bar"
/>
bottom menu bar. 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:id="#+id/relativeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottom_nav"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:menu="#menu/bottom_nav_menu" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/fab_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="#dimen/margin_padding"
android:src="#drawable/ic_add"
android:tint="#color/colorWhite"
app:backgroundTint="#color/colorPrimary"
app:layout_anchor="#id/bottom_nav"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:elevation="#dimen/floating_b_ele"
android:clickable="true"
android:focusable="true"
/>
</androidx.constraintlayout.widget.ConstraintLayout>

add a layout_marginBottom to the RecyclerView which is equal to the height of the bottom navigation

Related

How to set position floatingactionbutton abave bottom bar

I have activity with FloatingActionButton and BottomNavigationView.
I want FloatingActionButton have position above BottomNavigationView. but no matter what I do, it is always with BottomNavigationView like on img
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.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=".MainActivity2">
<fragment
android:id="#+id/nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
app:defaultNavHost="true"
app:navGraph="#navigation/mobile_navigation" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_margin="16dp"
android:src="#drawable/ic_baseline_addchart_24" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/yu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottom_bar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:menu="#menu/bottom_menu" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Place FAB button inside the constraint layout and then set the property
app:layout_constraintTop_toBottomOf="#id/fab"
to your Navigation View and
app:layout_constraintBottom_toTopOf="#id/bottom_bar"
android:layout_margin="16dp"
In this way the FAB button will always stay on top of navigation view.
here you go just replace it with your floatbutton tag
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_marginBottom="70dp"
android:layout_marginEnd="16dp"
android:src="#drawable/ic_baseline_addchart_24" />
the bottom navigation is almost 56dp height so what we did is we added 70dp to marginBottom to lift it above the navigation and it will stay there always, you can change that value as your likings :)

Custom bottom navigation bar layout new

I want to create the following customized BottomNavigationBar. How can I set custom layout for the same?
enter image description here
This is actually a combination of a bottom navigation and a floating action button.
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.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=".MainActivity">
<com.google.android.material.bottomappbar.BottomAppBar
android:id="#+id/bottomAppBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:fabCradleMargin="20dp"
app:fabCradleVerticalOffset="10dp"
app:fabCradleRoundedCornerRadius="20dp"
android:layout_gravity="bottom">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottomNavigationView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginEnd="16dp"
android:background="#android:color/transparent"
app:menu="#menu/bottom_nav_menu" />
</com.google.android.material.bottomappbar.BottomAppBar>
<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/bottomAppBar" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Add this in the Main Activity
bottomNavigationView.background = null
bottomNavigationView.menu.getItem(2).isEnabled = false
Youtube link for fab in middle

How to hide BottomNavigationView when recylerview scrolls up

Hello there I want to hide bottom nav when recylerview scrolls up but not when the recylerview is scrolled down and when the recylerview stop I want the bottom nav to appear
also like a slide animation like how a bottom sheet has
I have one main activity in which I have given bottom nav and a fragment container as an Include the fragment container contains all of my fragments
Here is my code
Note if anyone wants more reference of the code please tell me i will
update the question
ok i have used app:layout_behavior="#string/hide_bottom_view_on_scroll_behavior" in bootom nav xml but its not working
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/black"
tools:context=".MainActivity">
<include
android:id="#+id/fragment_container"
layout="#layout/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<include
android:id="#+id/bottom_navigation_view"
layout="#layout/bottom_navigation_view" />
</RelativeLayout>
bottom_nav_view.xml
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.bottomnavigation.BottomNavigationView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/bottom_navigation_view_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginStart="30dp"
android:layout_marginEnd="30dp"
android:layout_marginBottom="10dp"
android:background="#drawable/bottom_navigation_style"
android:elevation="5dp"
app:itemIconSize="30dp"
app:itemIconTint="#color/white"
app:itemRippleColor="#android:color/transparent"
app:labelVisibilityMode="unlabeled"
app:layout_behavior="#string/hide_bottom_view_on_scroll_behavior"
app:menu="#menu/bottom_navigation">
</com.google.android.material.bottomnavigation.BottomNavigationView>
You need to use CoordinatorLayout to achieve this "scroll-hide" feature:
<androidx.coordinatorlayout.widget.CoordinatorLayout //root Layout
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">
<androidx.core.widget.NestedScrollView //or RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/main_linearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" />
</androidx.core.widget.NestedScrollView>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/main_bottomNavigationView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="#android:color/white"
app:layout_behavior="com.google.android.material.behavior.HideBottomViewOnScrollBehavior"
app:menu="#menu/main" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Demo: https://youtu.be/3Gpeg6M82n4

Add Navigation Drawer with Bottom Navigation Bar

In my app there is Bottom Navigation Bar i want to add Navigation Drawer because there is many buttons that dont fit at Bottom Navigation Bar.
i tried many ways but unfortunately none of them worked
here is my Bottom Navigation Bar xml code
<?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/colorAccent2"
tools:context=".UI.HomeActivity"
tools:layout_editor_absoluteY="81dp">
<FrameLayout
android:id="#+id/frame1"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="8dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="0dp"
app:layout_constraintBottom_toTopOf="#+id/navigationView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_chainStyle="spread_inside">
</FrameLayout>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/navigationView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="#fcff38"
app:itemIconTint="#000000"
app:itemTextColor="#303132"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/frame1"
app:menu="#menu/menu" />
</androidx.constraintlayout.widget.ConstraintLayout>
Any answer could help,
Thanks.
You need to add 'NavigationView' class in the layout, also wrap the root view group inside DrawerLayout.
<androidx.drawerlayout.widget.DrawerLayout>
<androidx.constraintlayout.widget.ConstraintLayout>
<FrameLayout
...
</FrameLayout>
<com.google.android.material.bottomnavigation.BottomNavigationView/>
</androidx.constraintlayout.widget.ConstraintLayout>
<com.google.android.material.navigation.NavigationView />
</androidx.drawerlayout.widget.DrawerLayout>
This post will help you: NavigationView

How to hide a layout behind another component within xml?

I would like to hide a layout behind another component in my activity_main.xml. I am using a bottom sheet and would only like to view the top portion. The bottom should be hidden behind my toolbar. Is there a function or property that will push the layout behind the component?
main_activity.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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<fragment
android:id="#+id/top_app_bar"
android:name="com.ds.base.fragments.TopAppBarFragment"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_constraintBottom_toTopOf="#+id/include"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_chainStyle="spread" />
<include
android:id="#+id/include"
android:layout_height="0dp"
android:layout_width="match_parent"
layout="#layout/content_main"
app:layout_constraintBottom_toTopOf="#+id/main_bottom_app_bar"
app:layout_constraintStart_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#+id/top_app_bar"/>
<fragment
android:id="#+id/main_bottom_app_bar"
android:name="com.ds.base.fragments.BottomAppBarFragment"
android:layout_width="match_parent"
android:layout_height="90dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="#+id/include">
</fragment>
<include
android:id="#+id/time_remaining_layout"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
layout="#layout/time_remaining_bottom_sheet"
app:layout_constraintTop_toTopOf="#id/main_bottom_app_bar"/>
</androidx.constraintlayout.widget.ConstraintLayout>
use in xml
android:visibility="gone"
or
android:visibility="invisible"
also use in java(activity) code
view.setVisibility(View.INVISIBLE);
or
view.setVisibility(View.GONE);
To bring any View to top, You have to call
yourView.bringToFront()

Categories

Resources