第一个:makovkastar/FloatingActionButton
gihub:makovkastar/FloatingActionButton
实现的功能
当AbsListView
、RecyclerView
、ScrollView
向上滚动的时候,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
usingandroid: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
包含控件:FloatingActionsMenu
、FloatingActionButton
、AddFloatingActionButton
。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