修改Android FloatingActionButton的title的文字颜色及背景颜色实例详解

所属分类: 软件编程 / Android 阅读数: 34
收藏 0 赞 0 分享

修改Android FloatingActionButton的title的文字颜色及背景颜色实例详解

首先看一张图片

这里写图片描述

我是在一个不错的开源的FloatingActionButton库基础上实现的,链接github开源库 参考图片的标记和代码里的注释。代码如下:

<com.getbase.floatingactionbutton.FloatingActionsMenu
      android:id="@+id/fab_meau"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignParentBottom="true"
      android:layout_alignParentRight="true"
      android:layout_alignParentEnd="true"
      fab:fab_addButtonColorNormal="@color/theme_color" //修改meau按钮的背景色
      fab:fab_addButtonColorPressed="@color/fab_pressed_color" //meau按钮按下的颜色
      fab:fab_addButtonPlusIconColor="@color/white" //meau中间 "+" 的颜色
      fab:fab_labelStyle="@style/fab_labels_style" //title样式,可以修改title的颜色和背景
      android:layout_marginBottom="16dp"
      android:layout_marginRight="16dp"
      android:layout_marginEnd="16dp">

      <com.getbase.floatingactionbutton.FloatingActionButton
        android:id="@+id/fab_action_a"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        fab:fab_colorNormal="@color/white"
        fab:fab_title="联系客服发布信息" //button的标题
        fab:fab_size="mini" //normal和mini两个值,normal和meau一样大
        />

      <com.getbase.floatingactionbutton.FloatingActionButton
        android:id="@+id/fab_action_b"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        fab:fab_colorNormal="@color/white"
        fab:fab_title="个人发布信息"
        fab:fab_size="mini" 
        fab:fab_colorPressed="@color/fab_pressed_color"
        />

    </com.getbase.floatingactionbutton.FloatingActionsMenu>

在value.xml配置样式fab_labels_style代码如下:

<style name="fab_labels_style">
    <item name="android:background">@drawable/fab_label_background</item> //文字背景的样式
    <item name="android:textColor">@color/black</item> //文字的颜色
  </style>

drawable文件夹下的fab_label_background.xml代码如下:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
  <solid android:color="@color/white"/>
  <padding
    android:left="16dp"
    android:top="4dp"
    android:right="16dp"
    android:bottom="4dp"/> //离内边框的距离
  <corners
    android:radius="5dp"/> //边框四个叫的弧度

  <stroke
    android:width="1dp"
    android:color="@color/text_color_84"/> //边框边线的宽度和颜色
</shape>

搜了网上修改FloatingActionButton的title颜色,结果没有搜到,解决了问题后总结一下。

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

更多精彩内容其他人还在看

android byte[] 和short[]转换的方法代码

这篇文章主要介绍了android byte[] 和short[]转换的方法代码,有需要的朋友可以参考一下
收藏 0 赞 0 分享

Android获取应用程序大小的方法

这篇文章主要介绍了Android获取应用程序大小的方法,有需要的朋友可以参考一下
收藏 0 赞 0 分享

Android获取其他包的Context实例代码

这篇文章主要介绍了Android获取其他包的Context实例代码,有需要的朋友可以参考一下
收藏 0 赞 0 分享

Android放大镜的实现代码

这篇文章主要介绍了Android放大镜的实现代码,有需要的朋友可以参考一下
收藏 0 赞 0 分享

Android 读取Properties配置文件的小例子

这篇文章主要介绍了Android 读取Properties配置文件的小例子,有需要的朋友可以参考一下
收藏 0 赞 0 分享

Android通讯录开发之删除功能的实现方法

这篇文章主要介绍了Android通讯录开发之删除功能的实现方法,有需要的朋友可以参考一下
收藏 0 赞 0 分享

使用ViewPager实现android软件使用向导功能实现步骤

现在的大部分android软件,都是使用说明,就是第一次使用该软件时,会出现向导,可以左右滑动,然后就进入应用的主界面了,下面我们就实现这个功能
收藏 0 赞 0 分享

android在异步任务中关闭Cursor的代码方法

android在异步任务中如何关闭Cursor?在我们开发应用的时候,很多时候会遇到这种问题,下面我们就看看代码如何实现
收藏 0 赞 0 分享

Android自定义桌面功能代码实现

android自定义桌面其实很简单,看一个例子就明白了
收藏 0 赞 0 分享

android将图片转换存到数据库再从数据库读取转换成图片实现代码

有时候我们想把图片存入到数据库中,尽管这不是一种明智的选择,但有时候还是不得以会用到,下面说说将图片转换成byte[]数组存入到数据库中去,并从数据库中取出来转换成图像显示出来
收藏 0 赞 0 分享
查看更多