How to create a floating action button (FAB) in android, using AppCompat v21?

前端 未结 7 952
眼角桃花
眼角桃花 2020-11-30 18:03

I would like to create a floating action button (to add items to a listview), like google calendar, maintaining compatibility with pre-lollipop Android versions (before 5.0)

相关标签:
7条回答
  • 2020-11-30 19:05

    There is no longer a need for creating your own FAB nor using a third party library, it was included in AppCompat 22.

    https://developer.android.com/reference/android/support/design/widget/FloatingActionButton.html

    Just add the new support library called design in in your gradle-file:

    compile 'com.android.support:design:22.2.0'
    

    ...and you are good to go:

    <android.support.design.widget.FloatingActionButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:layout_margin="16dp"
            android:clickable="true"
            android:src="@drawable/ic_happy_image" />
    
    0 讨论(0)
提交回复
热议问题