Material Design : FloatingActionButton相关的开源库

第一个:makovkastar/FloatingActionButton

gihub:makovkastar/FloatingActionButton
这里写图片描述

实现的功能

AbsListViewRecyclerViewScrollView 向上滚动的时候,Fab消失;
当向下滚动的时候,FAB出现。
**注意:**FAB的父布局必须是FrameLayout,RelativeLayout都无效。

Gradle

dependencies {
    compile 'com.melnykov:floatingactionbutton:1.3.0'
}

XML

<FrameLayout
    android:id="@+id/activity_main"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.cqc.floatingactionbutton01.MainActivity"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

    <!--还能在frameLayout中使用,在RelativeLayout中无效-->
    <com.melnykov.fab.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|right"
        android:layout_margin="16dp"
        android:src="@android:drawable/ic_input_add"
        app:fab_colorNormal="@color/colorAccent"
        app:fab_colorPressed="@color/colorPrimary"
        app:fab_colorRipple="@color/colorRipple"
        app:fab_type="normal"
        app:fab_shadow="false"/>
</FrameLayout>

记得加上:xmlns:app="http://schemas.android.com/apk/res-auto"

java

recyclerView.setLayoutManager(new LinearLayoutManager(context));
recyclerView.setAdapter(new MyAdapter());
fab.attachToRecyclerView(recyclerView);

其它

  • Set the button type (normal or mini) via the fab_type xml attribute (default is normal):

    fab:fab_type="mini"

    or

    fab.setType(FloatingActionButton.TYPE_MINI);
  • Set the normal and pressed colors via the xml attributes:

    fab:fab_colorNormal="@color/primary"
    fab:fab_colorPressed="@color/primary_pressed"

    or

    fab.setColorNormal(getResources().getColor(R.color.primary));
    fab.setColorPressed(getResources().getColor(R.color.primary_pressed));
  • Enable/disable the button shadow with the fab_shadow xml attribite (it’s enabled by default):

    fab:fab_shadow="false"

    or

    fab.setShadow(false);
  • Show/hide the button expliciltly:

    fab.show();
    fab.hide();
    
    fab.show(false); // Show without an animation
    fab.hide(false); // Hide without an animation
  • Specify the ripple color for API 21+:

    fab:fab_colorRipple="@color/ripple"

    or

    fab.setColorRipple(getResources().getColor(R.color.ripple));
  • Set an icon for the FloatingActionButton using android:src xml attribute. Use drawables of size 24dp as specified by [guidelines]. Icons of desired size can be generated with [Android Asset Studio].

源码

https://git.oschina.net/libraryDemo/FloatingActionButton01

futuresimple/android-floating-action-button

包含控件:FloatingActionsMenuFloatingActionButtonAddFloatingActionButton。menu可以包括fab+afab。
github:android-floating-action-button
这里写图片描述

xml属性

每个xml属性都有对应的代码设置方式。

xml说明
app:fab_size=normal、mini
app:fab_colorNormal=正常时的颜色
app:fab_colorPressed按下时的颜色

还有很多其它设置,以后用到了再看吧。



xml

<com.getbase.floatingactionbutton.FloatingActionsMenu
    android:id="@+id/fam1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <com.getbase.floatingactionbutton.FloatingActionButton
        android:id="@+id/fam1_fab1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@android:drawable/ic_dialog_map"/>

    <com.getbase.floatingactionbutton.AddFloatingActionButton
        android:id="@+id/fam1_afab1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:fab_colorNormal="@color/colorAccent"
        app:fab_colorPressed="@color/colorPrimary"/>

</com.getbase.floatingactionbutton.FloatingActionsMenu>

Demo源码

https://git.oschina.net/libraryDemo/FloatingActionButton02

Clans / FloatingActionButton

github :https://git.oschina.net/libraryDemo/FloatingActionButton02

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值