Set state of BottomSheetDialogFragment to expanded

“Note that you cannot call the method before view layouts.” The above text is the clue. Dialogs have a listener that is fired once the dialog is shown. The dialog cannot be shown if it isn’t laid out. So, in the onCreateDialog() of your modal bottom sheet (BottomSheetFragment), just before returning the dialog (or anywhere, … Read more

How to hide ToolBar when I scrolling content up?

you have to do many changes in your both layout. first use CoordinatorLayout in activity_main.XML like below(change theme as per your requirement). <?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” android:id=”@+id/main_content” android:layout_width=”match_parent” android:layout_height=”match_parent” android:fitsSystemWindows=”true”> <android.support.design.widget.AppBarLayout android:layout_width=”match_parent” android:layout_height=”wrap_content” android:theme=”@style/ThemeOverlay.AppCompat.Dark.ActionBar”> <android.support.v7.widget.Toolbar android:id=”@+id/toolbar” android:layout_width=”match_parent” android:layout_height=”?attr/actionBarSize” android:background=”?attr/colorPrimary” android:theme=”@style/ThemeOverlay.AppCompat.Dark.ActionBar” app:layout_scrollFlags=”scroll|enterAlways” app:popupTheme=”@style/ThemeOverlay.AppCompat.Light” /> </android.support.design.widget.AppBarLayout> <include layout=”@layout/content_main” /> </android.support.design.widget.CoordinatorLayout> in content_main.XML use android.support.v4.widget.NestedScrollView instead … Read more

InflateException with FloatingActionButton from Official Design Library

com.android.support:appcompat-v7:21+ added support for tinting widgets on devices running pre android 5.1 (API Level 21). To make use of it make sure you extend or set the AppCompat Theme and use app:backgroundTint instead of android:backgroundTint. Example: <android.support.design.widget.FloatingActionButton xmlns:app=”http://schemas.android.com/apk/res-auto” android:id=”@+id/fab” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:layout_margin=”16dp” android:src=”https://stackoverflow.com/questions/30870443/@drawable/icon” app:backgroundTint=”@color/accent” app:borderWidth=”0dp” />

Disabling User dragging on BottomSheet

It can be now no longer relevant, but I will leave it here: import android.content.Context import android.util.AttributeSet import androidx.coordinatorlayout.widget.CoordinatorLayout import android.view.MotionEvent import android.view.View import com.google.android.material.bottomsheet.BottomSheetBehavior @Suppress(“unused”) class LockableBottomSheetBehavior<V : View> : BottomSheetBehavior<V> { constructor() : super() constructor(context: Context, attrs: AttributeSet) : super(context, attrs) var swipeEnabled = true override fun onInterceptTouchEvent( parent: CoordinatorLayout, child: V, event: … Read more

How to disable BottomNavigationView shift mode?

Implementation of BottomNavigationView has condition: when there is more than 3 items then use shift mode. At this moment you cannot change it through existing API and the only way to disable shift mode is to use reflection. You’ll need helper class: import android.support.design.internal.BottomNavigationItemView; import android.support.design.internal.BottomNavigationMenuView; import android.support.design.widget.BottomNavigationView; import android.util.Log; import java.lang.reflect.Field; public class BottomNavigationViewHelper … Read more