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

所属分类: 软件编程 / Android 阅读数: 21
收藏 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实现悬浮窗体效果

这篇文章主要为大家详细介绍了Android实现悬浮窗体效果,显示悬浮窗口,窗口可以拖动,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
收藏 0 赞 0 分享

Andriod studio 打包aar 的方法

这篇文章主要介绍了Andriod studio 打包aar的方法,非常不错,具有一定的参考借鉴价值 ,需要的朋友可以参考下
收藏 0 赞 0 分享

Android加载loading对话框的功能及实例代码(不退出沉浸式效果)

这篇文章主要介绍了Android加载loading对话框的功能及实例代码,不退出沉浸式效果,本文通过实例代码给大家介绍的非常详细,具有一定的参考借鉴价值,需要的朋友可以参考下
收藏 0 赞 0 分享

Android中LayoutInflater.inflater()的正确打开方式

这篇文章主要给大家介绍了关于Android中LayoutInflater.inflater()的正确打开方式,文中通过示例代码介绍的非常详细,需要的朋友可以参考借鉴,下面随着小编来一起学习学习吧
收藏 0 赞 0 分享

Delphi在Android下使用Java库的方法

这篇文章主要介绍了Delphi在Android下使用Java库的方法,本文以Android的USB串口通讯库为例,给大家介绍的非常详细,具有一定的参考借鉴价值,需要的朋友可以参考下
收藏 0 赞 0 分享

Retrofit2日志拦截器的使用

这篇文章主要介绍了Retrofit2日志拦截器的使用,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
收藏 0 赞 0 分享

Android创建外部lib库及自定义View的图文教程

这篇文章主要给大家介绍了关于Android创建外部lib库及自定义View的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
收藏 0 赞 0 分享

Android分享微信小程序失败的一些事小结

这篇文章主要给大家介绍了关于Android分享微信小程序失败一些事,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
收藏 0 赞 0 分享

Android分享微信小程序技巧之图片优化

这篇文章主要给大家介绍了关于Android分享微信小程序技巧之图片优化的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
收藏 0 赞 0 分享

Android Viewpager实现无限循环轮播图

这篇文章主要为大家详细介绍了Android Viewpager实现无限循环轮播图,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
收藏 0 赞 0 分享
查看更多