Is there a native component for the Floating action button in Android Material Design?

穿精又带淫゛_ 提交于 2019-12-17 19:25:59

问题


My question revolves around the Floating action button that was introduced in Android Material Design.

There are many library offering this component on GitHub as:

  1. Android-floating-action-button
  2. FloatingActionButton
  3. CircularFloatingActionMenu
  4. Fab
  5. Floating-action-button

But my question is:

Is there a native component with the last release of android.support.vX that was built for Floating action button?

Components such as :

  • android.support.v7.cardview
  • android.support.v4.widget.DrawerLayout
  • android.support.v7.widget.RecyclerView
  • ...

回答1:


Today (29/05/2015) it is officially avaiable with the new Material Design support Library.

Just add this dependency to your build.gradle

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

Add this view to your layout:

<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:src="@drawable/ic_done" />

And use it:

FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        //TODO
    }
});



回答2:


Not yet, there have been hints that we will see it in the next support lib.




回答3:


You can use the class md-fab on a md-button then add a span with something like a plus sign inside of the md-button. Also there are other md-fab classes like md-fab-bottom-right which might help you out. Also you can use an md-icon inside your md-button

<md-button class="md-fab"><span class="glyphicon glyphicon-plus" /></md-button>



回答4:


All the above answers are now out of date.

FABS are available as part of Material Components for Android: https://material.io/develop/android/docs/getting-started/

Here is the class: https://developer.android.com/reference/com/google/android/material/floatingactionbutton/FloatingActionButton

Don't miss the Catalog app with working examples: https://github.com/material-components/material-components-android



来源:https://stackoverflow.com/questions/30483210/is-there-a-native-component-for-the-floating-action-button-in-android-material-d

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!