###介绍

Source Code中的介绍如下:

Floating action buttons are used for a special type of promoted action. They are distinguished
by a circled icon floating above the UI and have special motion behaviors related to morphing,
launching, and the transferring anchor point.

Floating action buttons come in two sizes: the default and the mini. The size can be
controlled with the {@code fabSize} attribute.

As this class descends from {@link ImageView}, you can control the icon which is displayed
via {@link # setImageDrawable(Drawable)}.

The background color of this view defaults to the your theme’s {@code colorAccent}. If you
wish to change this at runtime then you can do so via
{@link # setBackgroundTintList(ColorStateList)}.

@attr ref android.support.design.R.styleable#FloatingActionButton_fabSize

###属性值

属性值 意义
app:backgroundTint 设置背景颜色
app:fabSize 设置FAB的大小,主要有两个取值normal,mini
android:src 设置FAB的图标内容
app:rippleColor 设置FAB点击过程中的颜色
app:elevation 设置FAB正常情况下的阴影效果
app:pressedTranslationZ 设置FAB点击时的阴影大小
app:borderWidth 设置边框宽度
android:clickable 是否可点击true or false
app:layout_anchor 设置FAB的锚点,即以哪个控件为参照点设置位置
app:layout_anchorGravity 设置FAB相对锚点的位置,取值:top,bottom.left,right,center_vertical,fill_vertical, center_horizontal,fill_horizontal,center,fill,clip_vertical,clip_horizontal,start,end

###具体使用
布局文件
activity_main.xml

<?xml version="1.0" encoding="utf-8"?>                

布局中一共设置了3个FAB,一个在左下角,一个在右下角,一个设置了锚点,颜色可以自己调整,简单的用法就是这个样子,对应的onClick事件在MainActivity中实现。

代码文件
MainActivity.java

package mraz.com.appbardemo;import android.annotation.TargetApi;import android.os.Build;import android.os.Bundle;import android.support.v7.app.AppCompatActivity;import android.support.v7.widget.Toolbar;import android.view.View;public class MainActivity extends AppCompatActivity {    Toolbar toolbar;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        toolbar = (Toolbar) findViewById(R.id.toolbar);        setSupportActionBar(toolbar);    }    @TargetApi(Build.VERSION_CODES.LOLLIPOP)    public void leftClick(View view) {        toolbar.setTitle("Left FAB onClick");    }    public void rightClick(View view) {        toolbar.setTitle("Right FAB onClick");    }    public void topClick(View view) {        toolbar.setTitle("Top FAB onClick");    }}

###实际效果

更多相关文章

  1. 基于Android的邮件收发
  2. Android(安卓)MenuItem 设置文字颜色-TextColor的设置
  3. Android中播放视频
  4. android通知栏提示
  5. android UI自定义设计圆形ImageView
  6. Android(安卓)hex RGB 各种颜色值 colors.xml
  7. Android(安卓)解压zip文件
  8. android进度条对话框小例子
  9. android中表格绘图

随机推荐

  1. Android Studio 安装ASM插件
  2. Android消息机制不完全解析(下)
  3. Error:Could not find com.android.tools
  4. Android性能优化
  5. 关于在Android设置全局变量随时获取conte
  6. Android(安卓)笔记38: BAIDU MAP API GPS
  7. Android第一次引导页设置
  8. 实例详解Android文件存储数据方式
  9. 解决Android(安卓)Studio更新错误 Soluti
  10. android 设置进入全屏,取消全屏的几种方