当前位置:网站首页>完全自定义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>
边栏推荐
- 威纶通触摸屏如何在报警的同时,显示出异常数据的当前值?
- How does the Weiluntong touch screen display the current value of abnormal data while alarming?
- 虚拟地址空间
- pytorch手撕CNN
- Fatal error: cstring: No such file or directory
- KRONES克朗斯电源维修0-901-17-350-8技术概论
- STL-stack
- 这款可视化工具神器,更直观易用!太爱了
- 实例051:按位与
- LeetCode Daily 2 Questions 02: Reverse the words in a string (1200 each)
猜你喜欢
如何利用fiddler连接手机抓包APP
BM13 determines whether a linked list is a palindrome
实例050:随机数
链表相加(二)
MySQL学习笔记(2)——简单操作
How does the Weiluntong touch screen display the current value of abnormal data while alarming?
JS学习 2022080
MySQL performance schema性能分析实战
OneNote 教程,如何在 OneNote 中整理笔记本?
Leave a message with a prize | OpenBMB x Tsinghua University NLP: The update of the large model open class is complete!
随机推荐
Research on multi-element N-k fault model of power system based on AC power flow (implemented by Matlab code) [Power System Fault]
链表相加(二)
canvas
从零开始配置 vim(7)——自动命令
KRONES克朗斯电源维修0-901-17-350-8技术概论
响应式pbootcms模板运动健身类网站
Introduction to the use of counter instructions in Rockwell AB PLC RSLogix5000
Nodes in the linked list are flipped in groups of k
RK3399平台开发系列讲解(内核驱动外设篇)6.35、IAM20680陀螺仪介绍
罗克韦尔AB PLC RSLogix5000中计数器指令使用方法介绍
JS中使用正则表达式g模式和非g模式的区别
Splunk中解决数据质量问题常见日期格式化
LeetCode Daily 2 Questions 02: Reverse the words in a string (1200 each)
音乐播放器(未完成版本)
2021 IDEA creates web projects
二叉树 | 代码随想录学习笔记
STL-stack
Android | 安卓好用软件来袭,多御安全浏览器免费又强大
Btree索引和Hash索引
ASCII、Unicode和UTF-8