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. struts2 传递数组、List、Map

    struts2 传递数组.List.Map jsp文件 数组:     <s:textfield name="ages" value="a1">&l ...

  2. jsonp实现原理详细介绍

    主要是浏览器的同源同域(协议相同,域名相同及端口相同)策略需要使用跨域获取数据,故需要jsonp跨域获取数据.重点:img的src,link的href及script的src不遵循浏览器的同源同域策略, ...

  3. mysql复制的配置

    # 78服务器 server-id=78 # 从哪个数开始 auto_increment_offset=1  # 每次增加多少 auto_increment_increment=2 log-bin=m ...

  4. 在VNC中Xfce4中Tab键失效的解决方法

    说明 在Ubuntu Server 14.04上安装了xfce4桌面环境,但是却发现在终端中Tab键不能自动补齐(但是Ctrl + I 仍然可以用). 出现这种情况的原因是,由于Tab键的功能被窗口快 ...

  5. Android listview和ListAdapter搭配使用

    ListView时Android中自带的数据显示控件,要使用ListView填充数据,必须要通过适配器来填充,这里给大家介绍一下ListAdapter适配器,效果图如下: java源码: packag ...

  6. linux 试题

    1. 在Linux系统中,以 文件 方式访问设备 . 2. 某文件的权限为:drw-r--r--,用数值形式表示该权限,则该八进制数为: 644 ,该文件属性是 目录 . 3. 前台起动的进程使用 C ...

  7. 使用JSPatch平台热修复iosApp

    IOS产品开发中常常会遇到这种情况,线上发现一个严重bug,可能是一个crash,可能是一个功能无法使用,这时能做的只是赶紧修复Bug然后提交等待漫长的审核,即使申请加急也不会快到那里去,即使审核完了 ...

  8. Oracle数据库和DB2数据库分页SQL的区别举例

    --------------------------ORACLE数据库分页SQL举例------------------------------------------------ SELECT * ...

  9. 2010 word 如何新建目录

    首先插入一个bullet 填充内容,编好编号,选择文字,右键,然后选择相应的level,然后点击一级菜单reference, 然后点击table of contents, 选择某一个样式,然后插入成功 ...

  10. Sun Grid Engine (SGE)大型集群作业调度系统

    Oracle Grid Engine 作业调度系统的简介(目前为止我用过PBS和SGE) SGE作业调度系统学习笔记 SGE作业调度 USE of Sun Grid Engine(SGE) 待续~