FloatingActionButton 浮动按钮
16lz
2021-01-23
转载自http://blog.csdn.net/feiduclear_up/article/details/46500865
以上是三种不同效果的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的大小,背景颜色,阴影的深度等,我们可以通过如下属性来控制这些效果:
- app:fabSize :FloatingActionButton的大小,有两种赋值分别是 “mini” 和 “normal”,默认是“normal”.
- 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
注意点
- 不能通过 android:background 属性来改变 FloatingActionButton的背景颜色,只能通过app:backgroundTint属性改变,因为FloatingActionButton是继承自ImageView的。
更多相关文章
- Android属性动画-简单实例
- Android获取屏幕相关属性ScreenUtil
- android中属性动画 ObjectionAnimation
- Android五大布局详解及属性
- Android的supportV7中默认按钮的颜色设置
- Android-Module:AutoCompleteTextView常用XML属性
- Android 控件布局实现卡片效果,阴影效果
- Android属性动画(ObjectAnimator、PropertyValuesHolder、ValueA