FloatingActionButton项目在github上的主页:https://github.com/futuresimple/android-floating-action-button

FloatingActionButton使用简单,而且可以自定义颜色、大小、背景图片

项目构造:

下面是demo的代码(主要见sample):

布局:

  1 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
2 xmlns:fab="http://schemas.android.com/apk/res-auto"
3 android:layout_width="match_parent"
4 android:layout_height="match_parent"
5 android:background="@color/background" >
6
7 <com.getbase.floatingactionbutton.FloatingActionButton
8 android:id="@+id/pink_icon"
9 android:layout_width="wrap_content"
10 android:layout_height="wrap_content"
11 android:layout_alignParentBottom="true"
12 android:layout_centerHorizontal="true"
13 android:layout_marginBottom="16dp"
14 fab:fab_colorNormal="@color/pink"
15 fab:fab_colorPressed="@color/pink_pressed"
16 fab:fab_icon="@drawable/ic_fab_star" />
17
18 <TextView
19 style="@style/menu_labels_style"
20 android:layout_width="wrap_content"
21 android:layout_height="wrap_content"
22 android:layout_above="@id/pink_icon"
23 android:layout_centerHorizontal="true"
24 android:layout_marginBottom="48dp"
25 android:text="Text below button" />
26
27 <com.getbase.floatingactionbutton.AddFloatingActionButton
28 android:id="@+id/semi_transparent"
29 android:layout_width="wrap_content"
30 android:layout_height="wrap_content"
31 android:layout_above="@id/pink_icon"
32 android:layout_centerHorizontal="true"
33 android:layout_marginBottom="16dp"
34 fab:fab_colorNormal="@color/blue_semi_transparent"
35 fab:fab_colorPressed="@color/blue_semi_transparent_pressed"
36 fab:fab_plusIconColor="@color/white" />
37
38 <com.getbase.floatingactionbutton.FloatingActionButton
39 android:id="@+id/setter"
40 android:layout_width="wrap_content"
41 android:layout_height="wrap_content"
42 android:layout_above="@id/semi_transparent"
43 android:layout_centerHorizontal="true"
44 android:layout_marginBottom="16dp" />
45
46 <com.getbase.floatingactionbutton.AddFloatingActionButton
47 android:id="@+id/normal_plus"
48 android:layout_width="wrap_content"
49 android:layout_height="wrap_content"
50 android:layout_alignParentBottom="true"
51 android:layout_alignParentLeft="true"
52 android:layout_alignParentStart="true"
53 android:layout_marginBottom="16dp"
54 android:layout_marginLeft="16dp"
55 android:layout_marginStart="16dp"
56 fab:fab_colorNormal="@color/white"
57 fab:fab_colorPressed="@color/white_pressed"
58 fab:fab_plusIconColor="@color/half_black" />
59
60 <com.getbase.floatingactionbutton.FloatingActionsMenu
61 android:id="@+id/right_labels"
62 android:layout_width="wrap_content"
63 android:layout_height="wrap_content"
64 android:layout_above="@id/normal_plus"
65 android:layout_alignParentLeft="true"
66 android:layout_alignParentStart="true"
67 android:layout_marginLeft="16dp"
68 android:layout_marginStart="16dp"
69 fab:fab_addButtonColorNormal="@color/white"
70 fab:fab_addButtonColorPressed="@color/white_pressed"
71 fab:fab_addButtonPlusIconColor="@color/half_black"
72 fab:fab_addButtonSize="mini"
73 fab:fab_labelStyle="@style/menu_labels_style"
74 fab:fab_labelsPosition="right" >
75
76 <com.getbase.floatingactionbutton.FloatingActionButton
77 android:layout_width="wrap_content"
78 android:layout_height="wrap_content"
79 fab:fab_colorNormal="@color/white"
80 fab:fab_colorPressed="@color/white_pressed"
81 fab:fab_title="Label on the right" />
82
83 <com.getbase.floatingactionbutton.FloatingActionButton
84 android:layout_width="wrap_content"
85 android:layout_height="wrap_content"
86 fab:fab_colorNormal="@color/white"
87 fab:fab_colorPressed="@color/white_pressed"
88 fab:fab_size="mini"
89 fab:fab_title="Another one on the right" />
90 </com.getbase.floatingactionbutton.FloatingActionsMenu>
91
92 <com.getbase.floatingactionbutton.FloatingActionsMenu
93 android:id="@+id/multiple_actions"
94 android:layout_width="wrap_content"
95 android:layout_height="wrap_content"
96 android:layout_alignParentBottom="true"
97 android:layout_alignParentEnd="true"
98 android:layout_alignParentRight="true"
99 android:layout_marginBottom="16dp"
100 android:layout_marginEnd="16dp"
101 android:layout_marginRight="16dp"
102 fab:fab_addButtonColorNormal="@color/white"
103 fab:fab_addButtonColorPressed="@color/white_pressed"
104 fab:fab_addButtonPlusIconColor="@color/half_black"
105 fab:fab_labelStyle="@style/menu_labels_style" >
106
107 <com.getbase.floatingactionbutton.FloatingActionButton
108 android:id="@+id/action_a"
109 android:layout_width="wrap_content"
110 android:layout_height="wrap_content"
111 fab:fab_colorNormal="@color/white"
112 fab:fab_colorPressed="@color/white_pressed"
113 fab:fab_title="Action A" />
114
115 <com.getbase.floatingactionbutton.FloatingActionButton
116 android:id="@+id/action_b"
117 android:layout_width="wrap_content"
118 android:layout_height="wrap_content"
119 fab:fab_colorNormal="@color/white"
120 fab:fab_colorPressed="@color/white_pressed"
121 fab:fab_title="Action with a very long name that won\&apos;t fit on the screen" />
122 </com.getbase.floatingactionbutton.FloatingActionsMenu>
123
124 <com.getbase.floatingactionbutton.FloatingActionsMenu
125 android:id="@+id/multiple_actions_down"
126 android:layout_width="wrap_content"
127 android:layout_height="wrap_content"
128 android:layout_alignParentEnd="true"
129 android:layout_alignParentRight="true"
130 android:layout_alignParentTop="true"
131 android:layout_marginEnd="16dp"
132 android:layout_marginRight="16dp"
133 android:layout_marginTop="16dp"
134 fab:fab_addButtonColorNormal="@color/white"
135 fab:fab_addButtonColorPressed="@color/white_pressed"
136 fab:fab_addButtonPlusIconColor="@color/half_black"
137 fab:fab_addButtonSize="mini"
138 fab:fab_expandDirection="down"
139 fab:fab_labelStyle="@style/menu_labels_style" >
140
141 <com.getbase.floatingactionbutton.FloatingActionButton
142 android:layout_width="wrap_content"
143 android:layout_height="wrap_content"
144 fab:fab_colorNormal="@color/white"
145 fab:fab_colorPressed="@color/white_pressed"
146 fab:fab_size="mini" />
147
148 <com.getbase.floatingactionbutton.FloatingActionButton
149 android:id="@+id/button_remove"
150 android:layout_width="wrap_content"
151 android:layout_height="wrap_content"
152 fab:fab_colorNormal="@color/white"
153 fab:fab_colorPressed="@color/white_pressed"
154 fab:fab_title="Click to remove" />
155
156 <com.getbase.floatingactionbutton.FloatingActionButton
157 android:id="@+id/button_gone"
158 android:layout_width="wrap_content"
159 android:layout_height="wrap_content"
160 fab:fab_colorNormal="@color/white"
161 fab:fab_colorPressed="@color/white_pressed" />
162
163 <com.getbase.floatingactionbutton.FloatingActionButton
164 android:id="@+id/action_enable"
165 android:layout_width="wrap_content"
166 android:layout_height="wrap_content"
167 fab:fab_colorNormal="@color/white"
168 fab:fab_colorPressed="@color/white_pressed"
169 fab:fab_title="Set bottom menu enabled/disabled" />
170 </com.getbase.floatingactionbutton.FloatingActionsMenu>
171
172 <com.getbase.floatingactionbutton.FloatingActionsMenu
173 android:id="@+id/multiple_actions_left"
174 android:layout_width="wrap_content"
175 android:layout_height="wrap_content"
176 android:layout_alignParentTop="true"
177 android:layout_marginEnd="16dp"
178 android:layout_marginRight="16dp"
179 android:layout_marginTop="16dp"
180 android:layout_toLeftOf="@+id/multiple_actions_down"
181 android:layout_toStartOf="@+id/multiple_actions_down"
182 fab:fab_addButtonColorNormal="@color/white"
183 fab:fab_addButtonColorPressed="@color/white_pressed"
184 fab:fab_addButtonPlusIconColor="@color/half_black"
185 fab:fab_addButtonSize="mini"
186 fab:fab_addButtonStrokeVisible="false"
187 fab:fab_expandDirection="left" >
188
189 <com.getbase.floatingactionbutton.FloatingActionButton
190 android:layout_width="wrap_content"
191 android:layout_height="wrap_content"
192 fab:fab_colorNormal="@color/white"
193 fab:fab_colorPressed="@color/white_pressed" />
194
195 <com.getbase.floatingactionbutton.FloatingActionButton
196 android:layout_width="wrap_content"
197 android:layout_height="wrap_content"
198 fab:fab_colorNormal="@color/white"
199 fab:fab_colorPressed="@color/white_pressed"
200 fab:fab_size="mini" />
201
202 <com.getbase.floatingactionbutton.FloatingActionButton
203 android:layout_width="wrap_content"
204 android:layout_height="wrap_content"
205 android:visibility="gone"
206 fab:fab_colorNormal="@color/white"
207 fab:fab_colorPressed="@color/white_pressed"
208 fab:fab_size="mini" />
209 </com.getbase.floatingactionbutton.FloatingActionsMenu>
210
211 <com.getbase.floatingactionbutton.FloatingActionButton
212 android:id="@+id/setter_drawable"
213 android:layout_width="wrap_content"
214 android:layout_height="wrap_content"
215 android:layout_above="@id/setter"
216 android:layout_centerHorizontal="true" />
217
218 </RelativeLayout>

JAVA代码:

 1 package com.getbase.floatingactionbutton.sample;
2
3 import com.getbase.floatingactionbutton.FloatingActionButton;
4 import com.getbase.floatingactionbutton.FloatingActionsMenu;
5
6 import android.app.Activity;
7 import android.graphics.drawable.ShapeDrawable;
8 import android.graphics.drawable.shapes.OvalShape;
9 import android.os.Bundle;
10 import android.view.View;
11 import android.view.View.OnClickListener;
12 import android.widget.Toast;
13
14 public class MainActivity extends Activity {
15 @Override
16 protected void onCreate(Bundle savedInstanceState) {
17 super.onCreate(savedInstanceState);
18 setContentView(R.layout.activity_main);
19
20 findViewById(R.id.pink_icon).setOnClickListener(new OnClickListener() {
21 @Override
22 public void onClick(View v) {
23 Toast.makeText(MainActivity.this, "Clicked pink Floating Action Button", Toast.LENGTH_SHORT).show();
24 }
25 });
26
27 FloatingActionButton button = (FloatingActionButton) findViewById(R.id.setter);
28 button.setSize(FloatingActionButton.SIZE_MINI);
29 button.setColorNormalResId(R.color.pink);
30 button.setColorPressedResId(R.color.pink_pressed);
31 button.setIcon(R.drawable.ic_fab_star);
32 button.setStrokeVisible(false);
33
34 final View actionB = findViewById(R.id.action_b);
35
36 FloatingActionButton actionC = new FloatingActionButton(getBaseContext());
37 actionC.setTitle("Hide/Show Action above");
38 actionC.setOnClickListener(new OnClickListener() {
39 @Override
40 public void onClick(View v) {
41 actionB.setVisibility(actionB.getVisibility() == View.GONE ? View.VISIBLE : View.GONE);
42 }
43 });
44
45 final FloatingActionsMenu menuMultipleActions = (FloatingActionsMenu) findViewById(R.id.multiple_actions);
46 menuMultipleActions.addButton(actionC);
47
48 final FloatingActionButton removeAction = (FloatingActionButton) findViewById(R.id.button_remove);
49 removeAction.setOnClickListener(new OnClickListener() {
50 @Override
51 public void onClick(View v) {
52 ((FloatingActionsMenu) findViewById(R.id.multiple_actions_down)).removeButton(removeAction);
53 }
54 });
55
56 ShapeDrawable drawable = new ShapeDrawable(new OvalShape());
57 drawable.getPaint().setColor(getResources().getColor(R.color.white));
58 ((FloatingActionButton) findViewById(R.id.setter_drawable)).setIconDrawable(drawable);
59
60 final FloatingActionButton actionA = (FloatingActionButton) findViewById(R.id.action_a);
61 actionA.setOnClickListener(new OnClickListener() {
62 @Override
63 public void onClick(View view) {
64 actionA.setTitle("Action A clicked");
65 }
66 });
67
68 // Test that FAMs containing FABs with visibility GONE do not cause crashes
69 findViewById(R.id.button_gone).setVisibility(View.GONE);
70
71 final FloatingActionButton actionEnable = (FloatingActionButton) findViewById(R.id.action_enable);
72 actionEnable.setOnClickListener(new OnClickListener() {
73 @Override
74 public void onClick(View view) {
75 menuMultipleActions.setEnabled(!menuMultipleActions.isEnabled());
76 }
77 });
78
79 FloatingActionsMenu rightLabels = (FloatingActionsMenu) findViewById(R.id.right_labels);
80 FloatingActionButton addedOnce = new FloatingActionButton(this);
81 addedOnce.setTitle("Added once");
82 rightLabels.addButton(addedOnce);
83
84 FloatingActionButton addedTwice = new FloatingActionButton(this);
85 addedTwice.setTitle("Added twice");
86 rightLabels.addButton(addedTwice);
87 rightLabels.removeButton(addedTwice);
88 rightLabels.addButton(addedTwice);
89 }
90 }

colors:

 1 <?xml version="1.0" encoding="utf-8"?>
2 <resources>
3 <color name="black_semi_transparent">#B2000000</color>
4 <color name="background">#e5e5e5</color>
5 <color name="half_black">#808080</color>
6 <color name="white">#fafafa</color>
7 <color name="white_pressed">#f1f1f1</color>
8 <color name="pink">#e91e63</color>
9 <color name="pink_pressed">#ec407a</color>
10 <color name="blue_semi_transparent">#805677fc</color>
11 <color name="blue_semi_transparent_pressed">#80738ffe</color>
12 </resources>

FloatingActionButton增强版,一个按钮跳出多个按钮--第三方开源--FloatingActionButton的更多相关文章

  1. 伴随ListView、RecyclerView、ScrollView滚动滑入滑出小图标--第三方开源--FloatingActionButton

    FloatingActionButton在github上的项目主页是:https://github.com/makovkastar/FloatingActionButton 它的依赖包NineOldA ...

  2. 一个丰富的通知工具类 --第三方开源--NotifyUtil

    把NotifyUtil Copy进自己的项目就好 实现有八种,作者在Demo里全部演示齐了,分别是 普通类型通知(单行) 普通类型通知(多行) 消息列表通知(含双图标) 含大图类型通知 自定义视图通知 ...

  3. 个人永久性免费-Excel催化剂功能第60波-数据有效性验证增强版,补足Excel天生不足

    Excel在数据处理.数据分析上已经是公认的最好用的软件之一,其易用性和强大性也吸引无数的初中高级用户每天都在使用Excel.但这些优点的同时,也带出了一些问题,正因为其不同于一般的专业软件,需要专业 ...

  4. 将表里的数据批量生成INSERT语句的存储过程 增强版

    将表里的数据批量生成INSERT语句的存储过程 增强版 有时候,我们需要将某个表里的数据全部或者根据查询条件导出来,迁移到另一个相同结构的库中 目前SQL Server里面是没有相关的工具根据查询条件 ...

  5. WinNTSetup v3.8.7 正式版绿色增强版

    最强系统安装利器:WinNTSetup 现已更新至 v3.8.7 正式版!这次更新修复调整了诸多问题,新版非常好用接近完美!WinNTSetup 现在已经自带BCDBoot 选项,并且完全支持Wind ...

  6. 将表里的数据批量生成INSERT语句的存储过程 继续增强版

    文章继续 桦仔兄的文章 将表里的数据批量生成INSERT语句的存储过程 增强版 继续增强... 本来打算将该内容回复于桦仔兄的文章的下面的,但是不知为何博客园就是不让提交!.... 所以在这里贴出来吧 ...

  7. 《zw版·delphi与halcon系列原创教程》zw版_THOperatorSetX控件函数列表 v11中文增强版

    <zw版·delphi与halcon系列原创教程>zw版_THOperatorSetX控件函数列表v11中文增强版 Halcon虽然庞大,光HALCONXLib_TLB.pas文件,源码就 ...

  8. zw版_zw中文增强版Halcon官方Delphi例程

    [<zw版·delphi与halcon系列原创教程>zw版_zw中文增强版Halcon官方Delphi例程 源码下载:http://files.cnblogs.com/files/ziwa ...

  9. hdu 1024(最大和连续子序列增强版)

    题意:最大和连续子序列的增强版,要求从一序列中取出若干段,这些段之间不能交叉,使得和最大并输出. 分析:用dp[i][j]表示前j个数取出i段得到的最大值,那么状态转移方程为dp[i][j]=max( ...

随机推荐

  1. Oracle 中取当前日期的上个月最后天和第一天

    前一月 最后一天select last_day(add_months(sysdate,-1)) from dual;               2010-2-28 9:23:01; select t ...

  2. oracle dba 职责, 及个人需要掌握内容

    ORACLE DBA 职责, 基本相当于日常工作. 0. 数据库设计 1. 模式对象的创建与管理(table, index 等等) 2. 事物管理, 例如并发等 3. SQL 调优 只是针对SQL的 ...

  3. hdu3060Area2(任意多边形相交面积)

    链接 多边形的面积求解是通过选取一个点(通常为原点或者多边形的第一个点)和其它边组成的三角形的有向面积. 对于两个多边形的相交面积就可以通过把多边形分解为三角形,求出三角形的有向面积递加.三角形为凸多 ...

  4. JavaWeb学习总结(十二)--事务

    一.事务的介绍 1.1 什么是事务 银行转账!张三转10000块到李四的账户,这其实需要两条SQL语句: 给张三的账户减去10000元: 给李四的账户加上10000元. 如果在第一条SQL语句执行成功 ...

  5. [js] 非常好的面试题,学习了。。

    原文链接:http://www.cnblogs.com/xxcanghai/p/5189353.html

  6. android设置软键盘搜索键以及监听搜索键点击时发生两次事件的问题解决

    在输入框中加入android:imeOptions="actionSearch",调用软键盘时,回车键就会显示搜索二字. 我想在点击搜索时,跳转到下一个页面,但是调用setOnKe ...

  7. mybatis动态SQL中的sql片段

    在mybatis中通过使用SQL片段可以提高代码的重用性,如下情景: 1.创建动态SQL <sql id="sql_count">select count(*)< ...

  8. ionic 原生日历控件不支持,改用 datepicker-for-ionic

    具体参考地址 http://npm.taobao.org/package/datepicker-for-ionic

  9. The Network Adapter could not establish the connection问题研究

    最近一个项目会报上述错误,但也不是经常发生,所以很难跟踪,影响不是很大,但每次看到日志中这个错误就会不舒服,还是要想办法解决才是. 错误提示信息很明确是网络适配器不能创建连接. 查了很多资料,并且Or ...

  10. window2012 64bit 安装sqlserver2012 64bit调用excel的驱动安装

    如果电脑已经安装了32bit的office那么可以使用 管理员权限打开cmd,然会执行以下命令 AccessDatabaseEngine_X64.exe /passive