当前位置:网站首页>完全自定义MaterialButtonToggleGroup颜色。
完全自定义MaterialButtonToggleGroup颜色。
2022-08-10 22:45:00 【雨季余静】
MaterialButtonToggleGroup自定义:边框颜色,边框宽度,边框弧度,排列方式,文字按下抬起颜色,背景按下抬起颜色。
搜索好的都是教怎么用,而没有说明怎么替换颜色。我跟了一下style继承关系,替换了想要替换的颜色。
布局文件
<com.google.android.material.button.MaterialButtonToggleGroup android:id="@+id/toggleGroup" android:layout_width="wrap_content" android:layout_height="wrap_content" android:theme="@style/MyMaterialButtonToggleGroup" app:checkedButton="@id/btn1" app:singleSelection="true">
<com.google.android.material.button.MaterialButton android:id="@+id/btn1" style="@style/MyOutlinedButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="选项一" android:textSize="@dimen/sp18" />
<com.google.android.material.button.MaterialButton android:id="@+id/btn2" style="@style/MyOutlinedButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="选项二" android:textSize="@dimen/sp18" />
<com.google.android.material.button.MaterialButton android:id="@+id/btn3" style="@style/MyOutlinedButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="选项三" android:textSize="@dimen/sp18" />
</com.google.android.material.button.MaterialButtonToggleGroup>
style 文件
<!--选项卡style-->
<style name="MyMaterialButtonToggleGroup" parent="Widget.MaterialComponents.MaterialButtonToggleGroup"> <!--选项卡背景边框和选中颜色,如果MaterialButton设置边框颜色后无效--> <!--<item name="colorPrimary">@color/white</item>--> <!--排列方式--> <item name="android:orientation">horizontal</item> <!--左上角弧度--> <item name="cornerSizeTopLeft">@dimen/dp4</item> <!--右上角弧度--> <item name="cornerSizeTopRight">@dimen/dp4</item> <!--左下角弧度--> <item name="cornerSizeBottomLeft">@dimen/dp4</item> <!--右下角弧度--> <item name="cornerSizeBottomRight">@dimen/dp4</item> </style>
<!--选项卡内部按钮颜色-->
<style name="MyOutlinedButton" parent="Widget.MaterialComponents.Button.OutlinedButton"> <!--边框颜色--> <item name="strokeColor">@color/white</item> <!--边框宽度--> <item name="strokeWidth">1dp</item> <!--文字按下抬起颜色--> <item name="android:textColor">@drawable/outline_text_color</item> <!--背景按下抬起颜色--> <item name="backgroundTint">@drawable/outline_bg_color</item> </style>
文字筛选器 outline_text_color.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!--选中颜色-->
<item android:alpha="1.00" android:color="@color/white" android:state_checkable="true" android:state_checked="true" android:state_enabled="true" />
<!--未选中颜色-->
<item android:alpha="1.00" android:color="@color/gray_C" android:state_checkable="true" android:state_checked="false" android:state_enabled="true" />
<item android:alpha="1.00" android:color="@color/white" android:state_enabled="true" />
<item android:alpha="1.00" android:color="@color/white" />
</selector>
背景筛选器 outline_bg_color.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!--选中颜色-->
<item android:alpha="0.3" android:color="@color/white" android:state_checked="true"/>
<!--未选中颜色-->
<item android:alpha="1.00" android:color="@android:color/transparent" android:state_checked="false"/>
</selector>
边栏推荐
猜你喜欢
RK3399平台开发系列讲解(内核驱动外设篇)6.35、IAM20680陀螺仪介绍
二叉树 | 对称二叉树、相同的树、子树相同 | leecode刷题笔记
常见的加密方式有哪几种,各有哪些优缺点
DC-8靶场下载及渗透实战详细过程(DC靶场系列)
金山云CEO王育林离职:正值冲刺港股之际 雷军曾送金砖
链表中的节点每k个一组翻转
LeetCode Daily 2 Questions 02: Reverse the words in a string (1200 each)
Qualcomm Platform Development Series Explanation (Application) Introduction to QCMAP Application Framework
2022年8月10日:使用 ASP.NET Core 为初学者构建 Web 应用程序--使用 ASP.NET Core 创建 Web UI(没看懂需要再看一遍)
风控逻辑利器---规则引擎
随机推荐
DC-7靶场下载及渗透实战详细过程(DC靶场系列)
留言有奖|OpenBMB x 清华大学NLP:大模型公开课更新完结!
威纶通触摸屏如何在报警的同时,显示出异常数据的当前值?
云服务器基于 SSH 协议实现免密登录
CFdiv2-Beautiful Mirrors-(期望)
《DevOps围炉夜话》- Pilot - CNCF开源DevOps项目DevStream简介 - feat. PMC成员胡涛
RK3399 platform development series explanation (kernel-driven peripherals) 6.35, IAM20680 gyroscope introduction
HanLP词性表
浅谈cors
This visual tool artifact is more intuitive and easy to use!love so much
怎么关闭电脑广告
RecyclerView上下滑动时,不调用onBindViewHolder 导致列表的item不刷新
geemap的详细安装步骤及环境配置
LeetCode每日两题02:反转字符串中的单词 (均1200道)
高通平台开发系列讲解(应用篇)QCMAP应用框架介绍
Pro-test is effective | A method to deal with missing features of risk control data
JS学习 2022080
koa框架(一)
pytorch手撕CNN
pytorch tear CNN