Move snackbar above the bottom bar
replace your xml ->
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.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/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="test.tab_activity">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="@+id/main_activity_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways">
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:id="@+id/placeSnackBar">
<android.support.v4.view.ViewPager
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_margin="@dimen/fab_margin"
android:src="@drawable/ic_menu_gallery" />
</android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.TabLayout
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="56dp"
android:background="?attr/colorPrimary" />
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
and The Snackbar code will be
Snackbar.make(findViewById(R.id.placeSnackBar), "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
Move snackbar above bottomNavigationView
In the google material component library you can use Snackbar
with anchor method like below:
Snackbar snackbar = Snackbar.make(view,"text",Snackbar.LENGTH_SHORT);
snackbar.setAnchorView(bottomNavigationView);
snackbar.show();
Move Snackbar above the bottomNavigationView
Resolve my problem with next solution:
private fun showNetworkMessage(isConnected: Boolean) {
if (!isConnected) {
val snack = Snackbar.make(
findViewById(R.id.container),
this.getText(R.string.warning_no_internet_connection), Snackbar.LENGTH_LONG
)
val params = snack.view.layoutParams as FrameLayout.LayoutParams
params.setMargins(0, 0, 0, this.resources.getDimension(R.dimen.action_bar_size).toInt())
snack.view.layoutParams = params
snack.show()
}
}
Where u can see i didn't use CoordinatorLayout
.
Fab not being pushed up by snackbar above bottom Navigation
Move the bottom nav to another layout and wrapped the CoordinatorLayout inside linear layout, now the snack bar should take CoordinatorLayout as root and CoordinatorLayout will have the fab at the bottom, So it would lift it when snack comes.
<LinearLayout 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:orientation="vertical"
tools:context=".MainActivity">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="@+id/snackRoot"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="16dp"
android:src="@drawable/ic_android_circle" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/design_default_color_secondary"
app:layout_insetEdge="bottom"
app:menu="@menu/menu" />
</LinearLayout>
show snack bar
Snackbar
.make(activity.findViewById(R.id.snackRoot),
"tttt",
Snackbar.LENGTH_LONG)
.show()
Snackbar under BottomNavigation
Add to your BottomNavigationView
this attribute:
app:layout_dodgeInsetEdges="bottom"
And invoke you SnackBar
with container as a view attibute:
Snackbar.make(container, "Snackbar", Snackbar.LENGTH_SHORT).show()
Related Topics
Sethinttextcolor() in Edittext
Redirect Users to Itunes App Store or Google Play Store
Error: Error Parsing Xml: Not Well-Formed (Invalid Token) ...
View Pager + Imageview +Pinch Zoom + Rotation
Detecting Outgoing Call and Call Hangup Event in Android
Invalid Heap Address and Fatal Signal 11
How to Add a View Programmatically to Relativelayout
Upload Photo Using Httppost Multipartentitybuilder
Upload Photo Using Httppost Multipartentitybuilder
Android Gcm Basic Implementation
Add Viewpagerindicator to Android Studio
How to Use a Library Project in Android Studio
How to Change System Navigation Bar Color
Draw a Semicircle in The Background of a View
Service Intent Must Be Explicit: Intent
Commitallowingstateloss() in Fragment Activities