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

所属分类: 软件编程 / Android 阅读数: 46
收藏 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网络编程之获取网络上的Json数据实例

这篇文章主要介绍了Android网络编程之获取网络上的Json数据实例,本文用完整的代码实例讲解了在Android中读取网络中Json数据的方法,需要的朋友可以参考下
收藏 0 赞 0 分享

Android中的windowSoftInputMode属性详解

这篇文章主要介绍了Android中的windowSoftInputMode属性详解,本文对windowSoftInputMode的9个属性做了详细总结,需要的朋友可以参考下
收藏 0 赞 0 分享

Android网络编程之UDP通信模型实例

这篇文章主要介绍了Android网络编程之UDP通信模型实例,本文给出了服务端代码和客户端代码,需要的朋友可以参考下
收藏 0 赞 0 分享

Android中使用ListView实现漂亮的表格效果

这篇文章主要介绍了Android中使用ListView实现漂亮的表格效果,本文用详细的代码实例创建了一个股票行情表格,需要的朋友可以参考下
收藏 0 赞 0 分享

Android中刷新界面的二种方法

这篇文章主要介绍了Android中刷新界面的二种方法,本文使用Handler、postInvalidate两种方法实现界面刷新,需要的朋友可以参考下
收藏 0 赞 0 分享

Android SDK三种更新失败及其解决方法

这篇文章主要介绍了Android SDK三种更新失败及其解决方法,需要的朋友可以参考下
收藏 0 赞 0 分享

Android学习笔记——Menu介绍(一)

Android3.0(API level 11)开始,Android设备不再需要专门的菜单键。随着这种变化,Android app应该取消对传统6项菜单的依赖。取而代之的是提供anction bar来提供基本的用户功能
收藏 0 赞 0 分享

Android学习笔记——Menu介绍(二)

这次将继续上一篇文章没有讲完的Menu的学习,上下文菜单(Context menu)和弹出菜单(Popup menu)
收藏 0 赞 0 分享

Android学习笔记——Menu介绍(三)

今天继续昨天没有讲完的Menu的学习,主要是Popup Menu的学习,需要的朋友可以参考下
收藏 0 赞 0 分享

Android显示网络图片实例

这篇文章主要介绍了Android显示网络图片的方法,以实例形式展示了Android程序显示网络图片的方法,非常具有实用价值,需要的朋友可以参考下
收藏 0 赞 0 分享
查看更多