RadioButton修改按钮颜色

RadioButton直接把backGround设置为selecter会整个背景变化,不美观!

只把边框和文字改变颜色怎么做呢

1 文字颜色直接使用textColor属性修改

2 radioButtom颜色使用buttonTint属性换色

这样就能做到原生美观的换色效果

 

demo:

<RadioButton
    android:id="@+id/rb_fence_round"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="圆形"
    android:checked="true"
    android:buttonTint="@color/white"
    android:textColor="@color/white" />
WPF中的RadioButton按钮的外观可以通过样式(Style)来自定义。以下是一个简单的样式示例,将RadioButton的外观更改为圆形按钮: ``` <Window.Resources> <Style x:Key="RadioButtonStyle" TargetType="{x:Type RadioButton}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type RadioButton}"> <Grid> <Ellipse x:Name="outerEllipse" Stroke="Black" StrokeThickness="2" Fill="White" /> <Ellipse x:Name="innerEllipse" Margin="4" Fill="Black" Opacity="0"/> <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" /> </Grid> <ControlTemplate.Triggers> <Trigger Property="IsChecked" Value="True"> <Setter TargetName="innerEllipse" Property="Opacity" Value="1"/> </Trigger> <Trigger Property="IsMouseOver" Value="True"> <Setter TargetName="outerEllipse" Property="Stroke" Value="DarkGray"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> </Window.Resources> <StackPanel> <RadioButton Content="Button1" Style="{StaticResource RadioButtonStyle}" /> <RadioButton Content="Button2" Style="{StaticResource RadioButtonStyle}" /> <RadioButton Content="Button3" Style="{StaticResource RadioButtonStyle}" /> </StackPanel> ``` 在这个样式中,我们使用了两个Ellipse元素来绘制外圆和内圆,使用ContentPresenter来显示RadioButton的内容。控件模板中的触发器用于更改内圆的透明度以及鼠标悬停时的外圆颜色。 这只是一个简单的样式示例,你可以按照自己的需求来自定义RadioButton的外观。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值