转载自http://blog.csdn.net/feiduclear_up/article/details/46500865

FloatingActionButton 浮动按钮_第1张图片

以上是三种不同效果的FloatingActionButton。XML布局代码如下:

  .support.design.widget.FloatingActionButton            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:src="@drawable/ic_discuss"             />
  • 1
  • 2
  • 3
  • 4
  • 5

由于FloatingActionButton是重写ImageView的,所有FloatingActionButton拥有ImageView的一切属性。为了

控制FloatingActionButton的大小,背景颜色,阴影的深度等,我们可以通过如下属性来控制这些效果:

  1. app:fabSize :FloatingActionButton的大小,有两种赋值分别是 “mini” 和 “normal”,默认是“normal”.
  2. app:backgroundTint:FloatingActionButton的背景颜色,默认的背景颜色是Theme主题中的
<item name="colorAccent">#ff0000
  • 1

颜色,不了解的童鞋们可以参考Android5.x新特性之 Toolbar和Theme的使用:http://blog.csdn.net/feiduclear_up/article/details/46457433。 
3. app:elevation :FloatingActionButton阴影的深度,默认是有阴影的,如果觉得默认阴影深度有点大,可以改变这个属性来修改阴影深度。

上面三个效果图的XML布局代码如下:

  "match_parent"        android:layout_height="wrap_content"        android:orientation="horizontal">        .support.design.widget.FloatingActionButton            android:id="@+id/btn"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:src="@drawable/ic_discuss"            app:fabSize="mini" />        .support.design.widget.FloatingActionButton            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:src="@drawable/ic_discuss"             />        .support.design.widget.FloatingActionButton            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:src="@drawable/ic_discuss"            app:backgroundTint="#000af4"            app:fabSize="normal"            app:elevation="1dp"             />    
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28

注意点

  1. 不能通过 android:background 属性来改变 FloatingActionButton的背景颜色,只能通过app:backgroundTint属性改变,因为FloatingActionButton是继承自ImageView的。

更多相关文章

  1. Android属性动画-简单实例
  2. Android获取屏幕相关属性ScreenUtil
  3. android中属性动画 ObjectionAnimation
  4. Android五大布局详解及属性
  5. Android的supportV7中默认按钮的颜色设置
  6. Android-Module:AutoCompleteTextView常用XML属性
  7. Android 控件布局实现卡片效果,阴影效果
  8. Android属性动画(ObjectAnimator、PropertyValuesHolder、ValueA

随机推荐

  1. Android(安卓)Studio下添加assets目录
  2. Android菜单详解
  3. android 获取路径目录方法
  4. 跟大家分享下Android布局文件layout.xml
  5. Android(安卓)对象序列化之你不知道的 Se
  6. Android:控件属性
  7. Android图标的制作
  8. Android(安卓)代码实现应用强制装到手机
  9. android 4.2修改设置菜单的背景颜色
  10. android studio查看模拟器文件夹