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. iOS - Threads 多线程

    1.Threads 1.1 进程 进程是指在系统中正在运行的一个应用程序.每个进程之间是独立的,每个进程均运行在其专用且受保护的内存空间内. 比如同时打开 QQ.Xcode,系统就会分别启动两个进程. ...

  2. iOS - ImageCache 网络图片缓存

    1.ImageCache 使用内存缓存方式: 使用沙盒缓存方式: 使用网络图片第三方库方式: SDWebImage: iOS 中著名的网络图片处理框架 包含的功能:图片下载.图片缓存.下载进度监听.g ...

  3. CDN学习笔记一(CDN是什么?)

    CDN是什么? 谈到CDN的作用,可以用8年买火车票的经历来形象比喻: 8年前,还没有火车票代售点一说,12306.cn更是无从说起.那时候火车票还只能在火车站的售票大厅购买,而我所住的小县城并不通火 ...

  4. iOS企业版打包(转载)

    转自 http://www.cnblogs.com/shenlaiyaoshi/p/5472474.html   神来钥匙-陈诗友 iOS 企业版 打包 使用 iOS 企业版的证书发布应用可以跳过 A ...

  5. linux下的挂载点和分区是什么关系

    Linux 使用字母和数字的组合来指代磁盘分区.这可能有些使人迷惑不解,特别是如果你以前使用“C 驱动器”这种方法来指代硬盘及它们的分区.在 DOS/Windows 的世界里,分区是用下列方法命名的: ...

  6. Git基本交互流程图

  7. Android开发面试经——1.常见人事面试问题

      Android开发(29)  版权声明:本文为寻梦-finddreams原创文章,请关注:http://blog.csdn.net/finddreams 做为程序员,我们都是有梦想的人,有时候当我 ...

  8. c/c++小知识

    1.printf计算参数时是从右到左 2.(int&)a 表示把a在内存中的值强行当作int数来处理 3.float四字节,1位符号位(正数为0),8位指数位(0采取01111111),23位 ...

  9. dbca建库时找不到ASM磁盘

    现象 dbca创建数据库时,找不到ASM磁盘组:而grid用户使用asmca却又能看到ASM磁盘组. 解决方法 1. 检查设备的权限,正确的权限为grid:asmadmin 2. 检查GRID_HOM ...

  10. 程序猿必知会的JavaScript 的遍历方式

    不管是移动移动端开发还是web端开发,我们对JS的使用频率都在增加,今天小编将要和大家分享的就是JavaScript中,遍历方式的一些实现方法,个人感觉还是很有用的,有兴趣的童鞋可以一起来看看. 为了 ...