2

Hi I am able to run bottom sheet on android 5.0 but not on kitkat.

Edited The strange thing is that when i presee recent app and open the app again it starts working? no clue O.o Here is my build.gradle

android {
    compileSdkVersion 23
    buildToolsVersion '23.0.2'

    defaultConfig {

        minSdkVersion 17
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
..}

View mBottomSheet = view.findViewById(R.id.location_bottom_sheet);
BottomSheetBehavior        mBehavior = BottomSheetBehavior.from(mBottomSheet);

        mBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
            @Override
            public void onStateChanged(@NonNull View bottomSheet, int newState) {

            }

            @Override
            public void onSlide(@NonNull View bottomSheet, float slideOffset) {

            }
        });

on Click i am doing this

final Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                mBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
                mBottomSheet.setVisibility(View.VISIBLE);
                handler.removeCallbacks(this);
            }
        }, 500);

still it is not working anyboyd have any idea why is this happening.

Jay Rathod
  • 11,131
  • 6
  • 34
  • 58
silentsudo
  • 6,730
  • 6
  • 39
  • 81

2 Answers2

0

I had exactly the same problem with KitKat and BottomSheet from 23.0.2. In my case it was caused by order of tags in the activity's xml. I placed the BottomSheet before map and in this case the BottomSheet was overlapped by the map on KitKat (but was not on Android 5). So to solve the problem you should do for example:

 <FrameLayout
        android:id="@+id/frameMain"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
...

 <android.support.v4.widget.NestedScrollView
        android:id="@+id/bottomSheet>
...

and not vice versa. Hope I'm specific enough:)

Alexandr
  • 695
  • 2
  • 9
  • 18
  • THe other thing i noticed was using linearlayout instead of framge layout as root container of bottomsheet – silentsudo Apr 19 '16 at 06:53
  • Here I created more comprehensive example: https://plnkr.co/edit/G7luSS0DHSJKMrVDoShN In fact my real layout is very large and complex but finally BottomSheet in this exmple is overlapped by Google Map fragment. This behaviour is reproduced on pre-lolipop devices only. – Alexandr Apr 19 '16 at 11:27
  • did you got bottom sheet working... can you please help me over here http://stackoverflow.com/questions/36985403/botomsheetdialog-fabbutton-anchor-view-not-working-as-expected/36986029 – silentsudo May 03 '16 at 06:22
0

This is the known issue as dicussed by google developers On some Pre-lollipop devices bottom sheet does not work

I found a solution after R&D for a day. Try this

  ViewCompat.postOnAnimation(yourCoordinator, new Runnable() {
            @Override
            public void run() {
                ViewCompat.postInvalidateOnAnimation(yourCoordinator);
            }
        });

Put this code after initializing views

Quick learner
  • 10,632
  • 4
  • 45
  • 55