BottomSheetBehavior not in androidX libraries

后端 未结 3 1009
渐次进展
渐次进展 2020-12-23 11:03

I was using the BottomSheetBehavior with the original support library:

implementation \'com.android.support:design:27.1.1\' 

W

相关标签:
3条回答
  • 2020-12-23 11:20

    You could also replace

        app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior"
    or 
        app:layout_behavior="android.support.design.widget.BottomSheetBehavior"
    

    by

    app:layout_behavior="@string/bottom_sheet_behavior"
    
    0 讨论(0)
  • 2020-12-23 11:43

    It turns out that the refactor tool in Android Studio Refactor > Migrate to AndroidX didn't correctly migrate the XML for the BottomSheetBehaviour.

    The old location was android.support.design.widget.BottomSheetBehavior, and was not modified by the migration tool. The original XML was:

    <fragment
        android:id="@+id/player_bottom_sheet_fragment"
        android:name="app.rxsongbrowsertrials.ui.player.PlayerToggleFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:behavior_hideable="false"
        app:behavior_peekHeight="56dp"
        app:layout_behavior="android.support.design.widget.BottomSheetBehavior"
        />
    

    The new location is com.google.android.material.bottomsheet.BottomSheetBehavior, so the layout needs to become:

    <fragment
        android:id="@+id/player_bottom_sheet_fragment"
        android:name="app.rxsongbrowsertrials.ui.player.PlayerToggleFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:behavior_hideable="false"
        app:behavior_peekHeight="56dp"
        app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior"
        />
    
    0 讨论(0)
  • 2020-12-23 11:43

    You have to import the Material Components Library provided by Google.

    Material Components for Android is a drop-in replacement for Android's Design Support Library.

    Add in your build.gradle:

    implementation 'com.google.android.material:material:x.x.x'
    

    Then use the class com.google.android.material.bottomsheet.BottomSheetBehavior.

    In your layout you can use the attribute:

        app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior"
        ..>
    

    or

    app:layout_behavior="@string/bottom_sheet_behavior"
    
    0 讨论(0)
提交回复
热议问题