Bottom Navigation view is not expanding in full space - android

I want to achieve something like this :
But when I am using this Bottom Navigation I am getting this, not able to replicate.
Both spacing and elevation are missing.
This is my Navigation view
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/nav_view"
android:layout_width="match_parent"
android:layout_height="68dp"
app:labelVisibilityMode="unlabeled"
android:background="#color/dark"
app:itemIconTint="#drawable/bottom_navigation_colors"
android:layout_alignParentBottom="true"
app:menu="#menu/bottom_nav_menu"
app:itemHorizontalTranslationEnabled="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:itemBackground="#drawable/bottom_navigation_colors"/>

Try removing the padding you specified in the Bottom Navigation Bar. Padding is used to specify the space/gap inside the container between its border and inside content. The padding attribute specified in the Navigation Bar may be pushing the menu items towards the center of the navigation bar. Removing the padding attribute should do the trick of evenly spacing the menu items across the navigation bar.

Related

Using NavigationView with SlidingPaneLayout

Per Google's Material Design guideline for Navigation drawer, to achieve Standard drawer for tablet or desktop devices, I would use NavigationView with SlidingPaneLayout for tablet devices instead of DrawerLayout for phone devices, which is to achieve Modal drawer.
I put a NavigationView as the first child view of SlidingPaneLayout. A problem occurred.
As you know SlidingPaneLayout's child views overlap if their combined width exceeds the available width in the SlidingPaneLayout. In this case, the child views expand to fill the available width in the SlidingPaneLayout. The user can slide the topmost view out of the way by dragging it back from the edge of the screen.
But my NavigationView's pane wouldn't slide. It just appears or disappears at maximum width without sliding animation.
How can I solve this?
<androidx.slidingpanelayout.widget.SlidingPaneLayout
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">
<!-- The first child view becomes the left pane. When the combined
desired width (expressed using android:layout_width) would
not fit on-screen at once, the right pane is permitted to
overlap the left. -->
<com.google.android.material.navigation.NavigationView
android:id="#+id/navigationView"
android:layout_width="280dp"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="#layout/navigation_view_header"
app:menu="#menu/navigation_view" />
<!-- The second child becomes the right (content) pane. In this
example, android:layout_weight is used to expand this detail pane
to consume leftover available space when the
the entire window is wide enough to fit both the left and right pane.-->
<fragment
android:id="#+id/navigationHost"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="320dp"
android:layout_weight="1"
android:layout_height="match_parent"
app:navGraph="#navigation/main" />
</androidx.slidingpanelayout.widget.SlidingPaneLayout>
Add app:elevation="0dp" to the NavigationView.
<com.google.android.material.navigation.NavigationView
android:id="#+id/navigationView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"
app:elevation="0dp"
app:headerLayout="#layout/navigation_view_header"
app:menu="#menu/navigation_view" />
If you inspect the layout, you can notice the NavigationView has elevation of 16dp by default. This causes the problem. It is probably that SlidingPaneLayout handles the two child views under the condition that they have the same elevations (0dp).
So a solution is to override NavigationView's default elevation (16dp) with 0dp.
Another solution is to wrap NavigationView with a FrameLayout or some ViewGroup.
<FrameLayout
android:layout_width="280dp"
android:layout_height="match_parent">
<com.google.android.material.navigation.NavigationView
android:id="#+id/navigationView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="#layout/navigation_view_header"
app:menu="#menu/navigation_view" />
</FrameLayout>
Then, you should specify layout_width with FrameLayout and NavigationView's layout_width to match_parent.
In spite of NavigationView's default elevation of 16dp, for its parent ViewGroup's elevation is 0dp, SlidingPaneLayout can properly handle.

BottomNavigationView does not follow layout heirarchy

I am having a bottom navigation view and I would want to hide it by showing a dummy view on top of it. In the relative layout, I am placing the dummy view on top of the bottom navigation view. But always the bottom navigation view shows on top. Why does the bottom navigation view does not follow layout hierarchy?
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_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"
android:background="#color/white"
android:theme="#style/BottomBar"
android:visibility="visible"
app:itemTextAppearanceActive="#style/BottomNavigationViewTextStyle"
app:itemTextAppearanceInactive="#style/BottomNavigationViewTextStyle"
app:labelVisibilityMode="labeled"
app:menu="#menu/bottom_navigation_menu" />
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:background="#color/black" />
</RelativeLayout>
I expect the View to be shown on top of the bottom navigation view(So that the bottom navigation view is invisible), but bottom navigation view always shown on top
Based on the following link https://material.io/components/bottom-navigation/android, the bottom navigation view has a default elevation of 8dp. Changing the elevation of dummy layout will fix the issue.

Remove the top padding in BottomNavigationView

I have a BottomNavigationView with a background showing for the selected item
Here's the bottom navigation XML:
<com.google.android.material.bottomnavigation.BottomNavigationView
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_gravity="bottom"
app:itemBackground="#drawable/bottombar_item_bg"/>
I want the items to match the bar height's and remove the top padding showing.
if I understand you true android:layout_height="?attr/actionBarSize" here you put height as 50dp so try change height to android:layout_height="35dp" or android:layout_height="40dp"

Align Text of BottomNavigationView to bottom or add margin

Used : BottomNavigationViewEx
Want to align Text or add margin of Bottom Navigation Tab. Not able to find method which will push Text of Bottom bit on edge of bottom.
Layout :
<FrameLayout
android:id="#+id/bottomNavigationViewLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<com.application.ui.view.BottomNavigationViewEx
android:id="#+id/bottomNavigationView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/login_orange"
android:elevation="16dp"
android:minHeight="60dp"
app:itemIconTint="#color/bottom_nav_item_state"
app:itemTextColor="#color/bottom_nav_item_state"
app:menu="#menu/bottom_nav_menu" />
</FrameLayout>
Tried :
Setting Icon Margin but it doesn't push text.
Need :
Align Text to Bottom or atleast add margin from Icon

Android - Force View to appear in front of Toolbar?

By default, eg. having Toolbar and some other Views in FrameLayout container causes Toolbar to appear on top of other views, no matter what their (views) order is.
Is it possible to force some of the views (eg. floating action buttons) to appear in front of Toolbar or should look for workaround?
edit:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fab="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="#layout/toolbar"/>
<!-- some RecyclerView goes here also -->
<com.github.clans.fab.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|right"
android:src="#drawable/ic_content_add"
fab:fab_colorNormal="#color/accentColor"
fab:fab_colorPressed="#color/accentColor"
android:layout_marginRight="20dp"
/>
</FrameLayout>
Result:
Problem: The oval button appears in front of RecyclerView, but behind Toolbar.
The floating action button has to have equal or higher elevation as the toolbar. Assuming your toolbar has elevation set to 8dp, the FAB needs to have the same at least.
Basically widgets with higher elevation move physically above and stop respecting the XML order.

Categories

Resources