FloatingActionButton控件初步使用

FloatingActionButton控件初步使用

Google推出了MaterialDesign的设计语言,其中FloatingActionButton就是一部分,但是Google却没有提供一个官方的FloatingActionButton控件,在github上找到一个比较好的插件,用它实现仿知乎的效果。
该控件理论上最低支持到API版本14也就是Android4.0(minSdkVersion 14),并且由于是官方Support Library中FloatingActionButton的二次封装,showdown的生成在API21以上和21以下并不太一样,所以在不同版本的系统中的效果会存在一定的差异。

使用

在Android studio中的Gradle配置中添加
compile ‘com.lzp.floatingactionbutton:floatingactionbuttonplus:1.0.0’即可。

xml文件布局

btns.xml

<com.lzp.floatingactionbuttonplus.FloatingActionButtonPlus
android:id="@+id/FabPlus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:switchFabColor="#DB4537"
app:switchFabIcon="@mipmap/ic_add_white_48dp"
app:layout_behavior="com.lzp.floatingactionbuttonplus.FabBehavior"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<com.lzp.floatingactionbuttonplus.FabTagLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:tagText="Download"
    >
    .support.design.widget.FloatingActionButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@mipmap/ic_get_app_white_48dp"
        app:backgroundTint="#468cb7"
        app:fabSize="mini" />
com.lzp.floatingactionbuttonplus.FabTagLayout>

<com.lzp.floatingactionbuttonplus.FabTagLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:tagText="Favorites"
    >
    .support.design.widget.FloatingActionButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@mipmap/ic_stars_white_48dp"
        app:backgroundTint="#818aa7"
        app:fabSize="mini" />
com.lzp.floatingactionbuttonplus.FabTagLayout>


<com.lzp.floatingactionbuttonplus.FabTagLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:tagText="Send mail"
    >
    .support.design.widget.FloatingActionButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@mipmap/ic_send_white_48dp"
        app:backgroundTint="#4BB7A7"
        app:fabSize="mini" />
com.lzp.floatingactionbuttonplus.FabTagLayout>

<com.lzp.floatingactionbuttonplus.FabTagLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:tagText="shopping list"
    >
    .support.design.widget.FloatingActionButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@mipmap/ic_shopping_cart_white_48dp"
        app:backgroundTint="#ff9800"
        app:fabSize="mini" />
com.lzp.floatingactionbuttonplus.FabTagLayout>

<com.lzp.floatingactionbuttonplus.FabTagLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:tagText="Search this page"
    >

    .support.design.widget.FloatingActionButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@mipmap/ic_search_white_48dp"
        app:backgroundTint="#4284E4"
        app:fabSize="mini" />
com.lzp.floatingactionbuttonplus.FabTagLayout>

com.lzp.floatingactionbuttonplus.FloatingActionButtonPlus>

activity_main.xml


<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
>

<include layout="@layout/btns" />
android.support.design.widget.CoordinatorLayout>  

效果图

你可能感兴趣的:(Android应用)