stop a specific views moving when the keyboard shows - android

i'm trying to stop the recycle view to be above the toolbar when i try to search and keyboard shows meanwhile make the fab visible(above the keyboard) ...
i have tried adjustResize and the adjustpan and stateAlwaysHiddenand toghther in manifast it doesn't work
so i want the recycle to be blocked and shows the fab after keyboard show
<?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:layout_gravity="bottom"
tools:context=".uivmodel.listfragment">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbarlist"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
android:theme="?attr/actionBarTheme"
android:title="#string/app_name"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:title="#string/app_name" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recycle"
android:layout_width="match_parent"
android:layout_height="720dp"
android:layout_marginHorizontal="30dp"
android:layout_marginTop="2dp"
android:fitsSystemWindows="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintEnd_toStartOf="#+id/toolbarlist"
app:layout_constraintHorizontal_bias="0.491"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/toolbarlist"
tools:itemCount="3"
tools:listitem="#layout/cutomadapterxml" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/addlist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:contentDescription="TODO"
android:fitsSystemWindows="true"
android:src="#drawable/ic_baseline_add_24"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.954"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

Related

how to hide bottomnavigation and app bar on scroll when app bar inside FragmentContainerView

I know we can hide bottomnavigation and app bar on scroll when both are the direct children of coordinate layout, But my issue is different, I have one home fragment and bottom view is a part of this fragment with FragmentContainerView, now my app bar inside the fragment which i am setting in container view, when i am scrolling, app bar getting scroll properly but i am not sure how to scroll bottom navigation as well,
home_fragment:
<?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">
<androidx.fragment.app.FragmentContainerView
android:id="#+id/rootFragmentContainer"
android:layout_width="match_parent"
android:layout_height="0dp"
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"
app:itemIconTint="#drawable/nav_bar_tab_color"
android:background="?android:attr/windowBackground"
app:itemTextAppearanceActive="#style/navText"
app:itemTextAppearanceInactive="#style/navText"
app:itemTextColor="#drawable/nav_bar_tab_color"
app:labelVisibilityMode="unlabeled"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:menu="#menu/navigation_items" />
</androidx.constraintlayout.widget.ConstraintLayout>
another fragment:
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<ProgressBar
android:id="#+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
/>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/layout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="#id/appbar"
app:layout_behavior="#string/appbar_scrolling_view_behavior" >
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/rvLay"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="#+id/rvProgressBar"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ProgressBar
android:id="#+id/rvProgressBar"
android:visibility="gone"
android:layout_width="0dp"
android:layout_height="50dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<com.google.android.material.appbar.AppBarLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:background="#color/colorWhite"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_collapseMode="pin"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="#style/ThemeOverlay.AppCompat" >
<androidx.appcompat.widget.AppCompatTextView
android:id="#+id/text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="#dimen/twentyfour_24dp"
android:paddingBottom="#dimen/eighteen_18dp"
android:text="#string/t2"
android:gravity="center"
android:textAllCaps="true"
style="#style/text_16px_franklin_gothic_normal_" />
</androidx.appcompat.widget.Toolbar>
</com.google.android.material.appbar.AppBarLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Can some one please explain me, how to achieve it?
Have you tried to add app:layout_behavior="#string/hide_bottom_view_on_scroll_behavior" inside your BottomNavigationView? In my case, it works just fine :)
I also suggest you to use CoordinatorLayout instead of ConstraintLayout in your home_fragment.xml

Delayed scrolling behavior in an app with scrolling "prominent top app bar" in Android

Current unexpected behaviour:
Required scrolling behaviour:
I’m experiencing some unexpected scrolling behaviour in an Android Kotlin app with a scrolling "prominent top app bar”. The desired behavior is for the whole contents of the inner fragment (with layout defined in fragment_trains.xml) to scroll as soon as the user scrolls down on that part of the screen.
The prominent top app bar starts scrolling immediately as intended. The unexpected scrolling behaviour is that there is a delay in the inner fragment contents scrolling. They don’t start scrolling until the prominent top app bar has completed scrolling and reached it’s “condensed” smaller size. How is it possible to resolve this issue? Solutions I have tried include adding focus tags to various parts of the layout, but haven’t been able to find any other answers related to this issue.
See layout XML, and screen recording showing the issue. The inner fragment should begin to scroll immediately rather than be delayed until the "prominent top app bar” has rested in to it’s smaller position. Even if it’s not possible to provide a solution to directly fix this, I haven’t been able to find example of an app layout like this with material design with a scrolling "prominent top app bar” and bottom navigation bar and a fragment in between with a scrolling behaviour. Thanks.
activity_main.xml:
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
android:id="#+id/nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:defaultNavHost="true"
app:layout_constraintBottom_toTopOf="#id/nav_view"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/appbar"
app:navGraph="#navigation/mobile_navigation" />
<com.google.android.material.appbar.AppBarLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="128dp"
app:liftOnScroll="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:focusable="false"
app:liftOnScrollTargetViewId="#id/nav_host_fragment">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:expandedTitleMarginStart="28dp"
app:expandedTitleMarginBottom="28dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed|snap"
app:contentScrim="?attr/colorPrimary"
app:statusBarScrim="?attr/colorPrimaryVariant"
app:expandedTitleTextAppearance="#style/Trains.TextAppearance.MaterialComponents.Headline6"
app:collapsedTitleTextAppearance="#style/Trains.TextAppearance.MaterialComponents.Headline6">
<com.google.android.material.appbar.MaterialToolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_scrollFlags="scroll|enterAlways|snap"
android:minHeight="80dp"
android:elevation="0dp"
android:title="#string/app_name"
app:layout_collapseMode="pin"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="#menu/top_app_bar"
style="#style/Widget.MaterialComponents.Toolbar.Primary"/>
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/nav_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary"
app:itemIconTint="#color/bnv_tab_item_foreground"
app:itemTextColor="#color/bnv_tab_item_foreground"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:layout_gravity="bottom"
app:menu="#menu/bottom_nav_menu" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
fragment_trains.xml:
<androidx.core.widget.NestedScrollView xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toTopOf="#+id/nav_view"
android:background="#color/colorBackground">
<LinearLayout
android:id="#+id/temp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="128dp"
android:orientation="vertical">
<!-- Travel info section -->
<TextView
android:id="#+id/text_travelinfoheader"
style="#style/TrainMediumCaption"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="29dp"
android:layout_marginLeft="29dp"
android:layout_marginTop="29dp"
android:layout_marginEnd="29dp"
android:layout_marginRight="29dp"
android:gravity="start"
android:textAlignment="gravity"
app:layout_constraintEnd_toEndOf="parent"
/>
<com.google.android.material.card.MaterialCardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="#+id/travelinfocard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="9dp"
android:layout_marginBottom="9dp"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"
card_view:cardCornerRadius="4dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:cardElevation="1dp"
app:layout_constraintTop_toBottomOf="#+id/text_travelinfoheader">
<TextView
android:id="#+id/text_travelinfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="19dp" />
</com.google.android.material.card.MaterialCardView>
<!-- Next trains section -->
<TextView
android:id="#+id/text_nexttrainheader"
style="#style/TrainMediumCaption"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="29dp"
android:layout_marginLeft="29dp"
android:layout_marginTop="9dp"
android:layout_marginEnd="29dp"
android:layout_marginRight="29dp"
android:gravity="start"
android:textAlignment="gravity"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/travelinfocard" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/nextrains_recyclerview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="9dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/text_nexttrainheader" />
</LinearLayout>
</androidx.core.widget.NestedScrollView>
To fix this issue, with the scrolling behaviour, this code:
app:layout_behavior="#string/appbar_scrolling_view_behavior"
needs to be moved from the NestedScrollView element in the fragment_trains.xml file, to the fragment element in the activity_main.xml file. Here are the new xml layout files to fix this issue:
New activity_main.xml:
<?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"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.appbar.AppBarLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="128dp"
app:liftOnScroll="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:focusable="false"
app:liftOnScrollTargetViewId="#id/nav_host_fragment"
>
<com.google.android.material.appbar.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:expandedTitleMarginStart="28dp"
app:expandedTitleMarginBottom="28dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed|snap"
app:contentScrim="?attr/colorPrimary"
app:statusBarScrim="?attr/colorPrimaryVariant"
app:expandedTitleTextAppearance="#style/Train.TextAppearance.MaterialComponents.Headline6"
app:collapsedTitleTextAppearance="#style/Train.TextAppearance.MaterialComponents.Headline6">
<com.google.android.material.appbar.MaterialToolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_scrollFlags="scroll|enterAlways|snap"
android:minHeight="80dp"
android:elevation="0dp"
android:title="#string/app_name"
app:layout_collapseMode="pin"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="#menu/top_app_bar"
style="#style/Widget.MaterialComponents.Toolbar.Primary"
/>
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>
<fragment
android:id="#+id/nav_host_fragment"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:defaultNavHost="true"
android:layout_marginBottom="110dp"
app:navGraph="#navigation/mobile_navigation" />
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/nav_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary"
app:itemIconTint="#color/bnv_tab_item_foreground"
app:itemTextColor="#color/bnv_tab_item_foreground"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:layout_gravity="bottom"
app:menu="#menu/bottom_nav_menu" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
New fragment_trains.xml:
<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorBackground">
<LinearLayout
android:id="#+id/temp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- Travel info section -->
<TextView
android:id="#+id/text_travelinfoheader"
style="#style/TrainMediumCaption"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="29dp"
android:layout_marginLeft="29dp"
android:layout_marginTop="29dp"
android:layout_marginEnd="29dp"
android:layout_marginRight="29dp"
android:gravity="start"
android:textAlignment="gravity"
app:layout_constraintEnd_toEndOf="parent"
/>
<com.google.android.material.card.MaterialCardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="#+id/travelinfocard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="9dp"
android:layout_marginBottom="9dp"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"
card_view:cardCornerRadius="4dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:cardElevation="1dp"
app:layout_constraintTop_toBottomOf="#+id/text_travelinfoheader">
<TextView
android:id="#+id/text_travelinfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="19dp" />
</com.google.android.material.card.MaterialCardView>
<!-- Next trains section -->
<TextView
android:id="#+id/text_nexttrainheader"
style="#style/TrainMediumCaption"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="29dp"
android:layout_marginLeft="29dp"
android:layout_marginTop="9dp"
android:layout_marginEnd="29dp"
android:layout_marginRight="29dp"
android:gravity="start"
android:textAlignment="gravity"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/travelinfocard" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/nextrains_recyclerview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="9dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/text_nexttrainheader" />
</LinearLayout>
</androidx.core.widget.NestedScrollView>
Here is the result, with the correct scrolling behaviour:

BottomNavigationView is visible even if view is top of it

I have screen with 3 main parts
toolbar
homeContaner(will host fragments of BottomNavigationView)
mainContainer (host splash screen or any screen that take full of screen)
when replace mainContainer with splash BottomNavigationView is also shown
I tried to add background color to mainContainer and found that BottomNavigationView is on Top of mainContainer
also tried to add elevation to mainContainer but got no new results
Screen shots
full 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"
tools:context=".feature.home_Activity.HomeActivity">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
app:titleTextColor="#android:color/white"/>
<FrameLayout
android:id="#+id/homeContainer"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="#id/dummy"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/toolbar" />
<View
android:id="#+id/dummy"
android:layout_width="match_parent"
android:layout_height="#dimen/_10sdp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#id/navigation" />
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:elevation="1dp"
app:layout_constraintBottom_toBottomOf="parent"
app:menu="#menu/navigation" />
<FrameLayout
android:id="#+id/mainContainer"
android:layout_width="0dp"
android:layout_height="0dp"
app:elevation="10dp"
android:background="#ffaaff"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Wrap BottomNavigationView with LinearLayout solved the problem
<?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=".feature.home_Activity.HomeActivity">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
app:layout_constraintTop_toTopOf="parent"
app:titleTextColor="#android:color/white" />
<FrameLayout
android:id="#+id/homeContainer"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="#id/dummy"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/toolbar" />
<View
android:id="#+id/dummy"
android:layout_width="match_parent"
android:layout_height="#dimen/_10sdp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#id/navigationContainer" />
<androidx.appcompat.widget.LinearLayoutCompat
android:id="#+id/navigationContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/bn_bg"
app:elevation="1dp"
app:itemBackground="#drawable/bn_item__bg"
app:itemIconTint="#color/secondaryTextColor"
app:itemTextColor="#color/primaryTextColor"
app:layout_constraintBottom_toBottomOf="parent"
app:menu="#menu/navigation" />
</androidx.appcompat.widget.LinearLayoutCompat>
<FrameLayout
android:id="#+id/mainContainer"
android:layout_width="0dp"
android:layout_height="0dp"
app:elevation="10dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

Floating Action Button is duplicated in fragment

In a project, there was a FloatingActionButton in one of the activities. I attempted to add a Fragment in that activity and move the FAB inside that Fragment. Everything seemed to be OK, however when I tried to display a SnackBar, I noticed there are two FloatingActionButtons instead of one in that area (One of them moving up with SnackBars).
In XML, there's only one FAB but when I run the app, two FABs appear which are on each other until a SnackBar is displayed. I'm trying to find the bug which caused the FAB to be duplicated.
Activity XML:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
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"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:id="#+id/fl_main_root"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/cl_main_toolbar"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize">
<androidx.appcompat.widget.Toolbar
android:id="#+id/tb_main_toolbar"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
android:background="#color/colorPrimary"
android:minHeight="?android:attr/actionBarSize"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
local:popupTheme="#style/ThemeOverlay.AppCompat.Light"
local:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"/>
<TextView
android:id="#+id/tv_main_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:textColor="#color/white"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
<fragment
android:id="#+id/f_main_memory"
android:name="ir.ali_kh_y.project.fragment.MemoryFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="?android:attr/actionBarSize"
android:layout_marginBottom="56dp"/>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bnv_main_nav"
android:layout_width="match_parent"
android:layout_height="56dp"
android:layout_gravity="bottom"
android:background="#color/colorPrimary"
app:itemIconTint="#color/bottom_nav_item_color_state"
app:itemTextColor="#color/bottom_nav_item_color_state"
app:labelVisibilityMode="unlabeled"
app:menu="#menu/bottom_nav"/>
</FrameLayout>
Fragment XML:
<?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:id="#+id/cl_memory_root"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".fragment.MemoryFragment">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/cl_memory_memories"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/rv_memory_memories"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="#ECEFF1"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<ImageView
android:id="#+id/iv_memory_smile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/empty_list"/>
<TextView
android:id="#+id/tv_memory_empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="8dp"
android:text="---"
android:textAlignment="center"
android:textColor="#color/emptyListContent"
android:textSize="30dp"
app:layout_constraintBottom_toTopOf="#+id/iv_memory_smile"
app:layout_constraintHorizontal_bias="0.504"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/fab_memory_write"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/fab_margin"
android:clickable="true"
android:focusable="true"
app:fabSize="normal"
app:layout_anchor="#+id/cl_memory_memories"
app:layout_anchorGravity="left|bottom"
app:rippleColor="#color/gray"
app:srcCompat="#drawable/ic_write"/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
The code I use in Activity to show Snack Bar:
val snackBar = Snackbar.make(cl_memory_root, "", Snackbar.LENGTH_INDEFINITE)
ViewCompat.setLayoutDirection(snackBar.view, ViewCompat.LAYOUT_DIRECTION_RTL)
snackBar.setAction("") {
//...
}
snackBar.show()
<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:id="#+id/cl_memory_root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff"
android:clickable="true"
tools:context=".fragment.MemoryFragment">
make background as white and make it clickable in the fragment and voila..
As Mike M mentioned, I was trying to load one Fragment twice, once from the code and once from the XML layout! So I deleted the one in the code and the duplication problem disappeared!

Overlay Toolbar with a Constraint layout for inApp Notification system

i'm searching a way for overlay the toolbar with a ConstraintLayout but it seems the toolbar have a priority over the ConstraintLayout
Layout:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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="#eaecf0"
tools:context="co.android.yalla.MainActivity">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:elevation="4dp"
android:theme="#style/Overlay"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light" />
<FrameLayout
android:id="#+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#eaecf0"
app:layout_constraintBottom_toTopOf="#+id/navigation"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/toolbar" />
<com.ittianyu.bottomnavigationviewex.BottomNavigationViewEx
android:id="#+id/navigation"
android:layout_width="match_parent"
android:layout_height="55dp"
android:background="#FFFFFF"
app:itemIconTint="#color/bottom_color"
app:itemTextColor="#color/bottom_color"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="#menu/bottom_navigation_items" />
<android.support.constraint.ConstraintLayout
android:id="#+id/notification"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/notification"
android:layout_marginTop="20dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="#+id/grey_pop_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:text="#string/d_selected_matches"
android:textColor="#android:color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
</android.support.constraint.ConstraintLayout>
I need to do this for a inApp Notification System
I've tried RelativeLayout and FrameLayout
I'm using the theme Theme.AppCompat.NoActionBar
I don't know if the Toolbar have some specific property about this problem
Thanks

Categories

Resources