安卓UI自定义radiobutton样式
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了安卓UI自定义radiobutton样式相关的知识,希望对你有一定的参考价值。
自己定义了一个radiobutton 的样式,但是在运行的时候自定义的样式和系统默认的样式同时显示了,请问要如何去掉或者隐藏系统默认的样式而只显示自定义的样式呢?
参考技术A自定义RadioButton样式分为两步:
1、自定义好样式:
打开style.xml,添加一个item
<style name="RadiobuttonStyle"><item name="android:gravity">center</item>
<item name="android:textSize">16sp</item>
<item name="android:textColor">@color/text_select_color</item>
<item name="android:button">@null</item>
<item name="android:drawableTop">@drawable/select_rbtn_home</item>
</style>
2、在RadioButon中引用:
<RadioButtonandroid:id="@+id/tv_tab_home"
style="@style/RadiobuttonStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:checked="true"
android:text="@string/tab_home" /> 参考技术B 在你的RadioButton控件下加上这句话
android:button="@null"
试试本回答被提问者和网友采纳 参考技术C 貌似你改的只是背景图而已
wpf radiobuttong 去前面的圆点, 自定义radiobutton样式
自定义radiobutton样式代码:
<windows.Resources>
<LinearGradientBrush x:Key="CheckRadioFillNormal">
<GradientStop Color="#FFD2D4D2" Offset="0"/>
<GradientStop Color="#FFFFFFFF" Offset="1"/>
</LinearGradientBrush>
<LinearGradientBrush x:Key="CheckRadioStrokeNormal">
<GradientStop Color="#FF004C94" Offset="0"/>
<GradientStop Color="#FF003C74" Offset="1"/>
</LinearGradientBrush>
<Style x:Key="CheckRadioFocusVisual">
<Setter Property="Control.Template">
<Setter.Value>
<ControlTemplate>
<Rectangle Margin="14,0,0,0" SnapsToDevicePixels="true" Stroke="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" StrokeThickness="1" StrokeDashArray="1 2"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="RadioButtonColorStyle" TargetType="{x:Type RadioButton}">
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
<Setter Property="Background" Value="{StaticResource CheckRadioFillNormal}"/>
<Setter Property="BorderBrush" Value="{StaticResource CheckRadioStrokeNormal}"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type RadioButton}">
<Grid>
<!--背景颜色 透明度 边框弧度-->
<Rectangle x:Name="rectangle" Fill="LightGray" Stroke="Black" Opacity="1" RadiusX="0" RadiusY="0" StrokeThickness="0"/>
<!--字体颜色, 字体大小-->
<TextBlock x:Name="textBlock" Margin="8,0" TextWrapping="Wrap" Text="{TemplateBinding Content}" HorizontalAlignment="Center" VerticalAlignment="Center" Height="27.137" FontSize="18.667" Foreground="Black"/>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="GroupName" Value=""/>
<Trigger Property="GroupName" Value=""/>
<!--鼠标点击触发器, 背景颜色-->
<Trigger Property="IsChecked" Value="True">
<Setter Property="Fill" TargetName="rectangle" Value="#8B0000"/>
<Setter Property="Opacity" TargetName="rectangle" Value="1"/>
<Setter Property="Foreground" TargetName="textBlock">
<Setter.Value>
<LinearGradientBrush>
<!--鼠标点击触发器, 修改字体颜色-->
<GradientStop Color="#FFFFFF" Offset="0"/>
<GradientStop Color="#FFFFFF" Offset="1"/>
</LinearGradientBrush>
</Setter.Value>
</Setter>
</Trigger>
<!--鼠标移入移出触发器-->
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Effect" TargetName="rectangle" Value="{x:Null}"/>
<Setter Property="Fill" TargetName="rectangle" Value="#AAAAAA"/>
</Trigger>
<Trigger Property="HasContent" Value="true">
<Setter Property="FocusVisualStyle" Value="{StaticResource CheckRadioFocusVisual}"/>
<Setter Property="Padding" Value="2,0,0,0"/>
</Trigger>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</windows.Resources>
调用radiobutton样式代码
<RadioButton Content="用户管理" Name="UserManager" FontSize="18" VerticalContentAlignment="Center" HorizontalAlignment="Stretch" Grid.Row="4" VerticalAlignment="Stretch" Margin="0,0,0,0" Checked="RBUserManager_Checked" Style="{DynamicResource RadioButtonColorStyle}"/>
以上是关于安卓UI自定义radiobutton样式的主要内容,如果未能解决你的问题,请参考以下文章
uniapp 给自定义组件或uview等ui组件加class样式或修改样式在微信小程序不生效的情况