可操作的浮动按钮使用

依赖库地址https://github.com/yavski/fab-speed-dial,

是一个可以展开的浮动按钮库,

使用如下:

1,创建项目并导入依赖库,

dependencies {
    compile 'io.github.yavski:fab-speed-dial:1.0.6'
}

2,项目中添加可操作的浮动按钮菜单m:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context="com.cui.fabspeeddial.MainActivity">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

    </android.support.design.widget.AppBarLayout>

    <include layout="@layout/content_main" />

    <io.github.yavski.fabspeeddial.FabSpeedDial
        android:id="@+id/fab_speed_dial"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        app:fabGravity="bottom_end"
        app:fabMenu="@menu/menu_fab"
        app:miniFabBackgroundTint="@android:color/white"
        app:miniFabDrawableTint="?attr/colorPrimaryDark"
        app:miniFabTitleTextColor="?attr/colorPrimaryDark" />

</android.support.design.widget.CoordinatorLayout>
很简单的使用这个按钮替代fab就行了,

其中app:fabGravity="bottom_end"就对应原来的layout_gravite;确定位置。

fabMenu是展开后的带单,多了会遮挡,三项比较好,

menu_fab.xml:

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context="com.cui.fabspeeddial.MainActivity">
    <item
        android:id="@+id/action_top"
        android:orderInCategory="100"
        android:title="顶部"
        android:icon="@drawable/ic_arrow_upward_black_24dp"
        app:showAsAction="never" />
    <item
        android:id="@+id/action_home"
        android:orderInCategory="100"
        android:icon="@drawable/ic_search_black_24dp"
        android:title="搜索"
        app:showAsAction="never" />
    <item
        android:id="@+id/action_settings"
        android:orderInCategory="100"
        android:icon="@drawable/ic_home_black_24dp"
        android:title="主页"
        app:showAsAction="never" />
</menu>
icon可以在

获得原生的svg图片。

其他的api见git地址,https://github.com/yavski/fab-speed-dial

3,代码中使用:

FabSpeedDial fabSpeedDial = (FabSpeedDial) findViewById(R.id.fab_speed_dial);
fabSpeedDial.setMenuListener(new SimpleMenuListenerAdapter() {
    @Override
    public boolean onPrepareMenu(NavigationMenu navigationMenu) {
        // TODO: Do something with yout menu items, or return false if you don't want to show them
        return true;
    }
});

fabSpeedDial.setMenuListener(new SimpleMenuListenerAdapter() {
    @Override
    public boolean onMenuItemSelected(MenuItem item) {
        //TODO: Start some activity

        int id = item.getItemId();
        switch (id){
            case R.id.action_top:
                 //TODO: Start some activity
break; case R.id.action_home: //TODO: Start some activity break; default:
               //TODO: Start some activity
break; } return false; }});
其他方法见原git地址https://github.com/yavski/fab-speed-dial

至此就完成了,

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值