The Material Design library is dependent on AppCompat. Check out @Booger answer. He reports on the official blog.
How to use FAB.
Add the dependency to your build.gradle :
compile 'com.android.support:design:22.2.0'
Just add FAB to your design:
<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_gravity="bottom|right" android:src="@drawable/ic_add" android:layout_marginBottom="@dimen/fab_margin_bottom" android:layout_marginRight="@dimen/fab_margin_right" app:elevation="6dp" app:borderWidth="0dp" app:fabSize="normal" />
There are currently some bugs.
You must define app:borderWidth="0dp" to display the shadow with API21 +.
You also need to define different fields for API 21+ and older devices.
RES / values ββ/ dens.xml
<dimen name="fab_margin_right">0dp</dimen> <dimen name="fab_margin_bottom">0dp</dimen>
RES / values-V21 / dens.xml
<dimen name="fab_margin_right">16dp</dimen> <dimen name="fab_margin_bottom">16dp</dimen>
FAB uses accent color, and you can override the app:backgroundTint attribute.
Finally, you can install ClickListener with:
fab = (FloatingActionButton) findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) {
source share