使用自定义选择时,删除默认单选按钮复选框自定义、单选、复选框、按钮

2023-09-07 09:05:52 作者:说太多卜如沉默

我试图风格单选按钮,所以我创建了一个选择。一切正常,除了标准的单选按钮,图像仍然显示。如何删除默认的单选按钮,复选框。我试着分配绘制为空字符串,但是编译器不喜欢它。

这是我选择的国家之一的code:

 <项目的android:state_checked =真正的机器人:可绘制=>    <形状和GT;        <梯度            机器人:startColor =#808080            机器人:centerColor =#2F2F2F            机器人:ENDCOLOR =#2F2F2F            机器人:角=270/>        <中风            机器人:宽=2DP            机器人:颜色=@彩色/黑白/>        <角落            机器人:半径=5DP/>    < /形状>< /项目> 

解决方案

我发现我不能删除默认单选按钮复选框中选择。我发现,它可以通过指定按钮属性设置为null,无论是在风格或单选按钮本身的定义中删除。

下面是使用样式的例子。

 <单选    机器人:ID =@ + ID / myRadioButton    风格=@风格/ RadioButtonStyle    机器人:layout_width =WRAP_CONTENT    机器人:layout_height =WRAP_CONTENT    机器人:文字=@字符串/ custom_radio_button/><样式名称=RadioButtonStyle父=@安卓风格/ Widget.CompoundButton>    <项目名称=机器人:背景> @绘制/ radiobutton_selector< /项目>    <项目名称=机器人:按钮> @空< /项目>< /风格> 
html css jq自定义复选框和单选按钮

radiobutton_selector定义绘制在不同的检查状态按钮的选择。这里是选中状态:

 <项目的android:state_checked =真正的>    <形状和GT;        <梯度            机器人:startColor =@彩色/ titleButtonCheckedGradientLight            机器人:centerColor =@彩色/ titleButtonCheckedGradientDark            机器人:ENDCOLOR =@彩色/ titleButtonCheckedGradientDark            机器人:角=270/>        <中风            机器人:宽=1DP            机器人:颜色=@色/ titleButtonBorder/>        <角落            机器人:半径=5DP/>    < /形状>< /项目> 

I am attempting to style a radio button and so I created a selector. Everything works except the standard radio button image still shows up. How do I remove the default radio button checkbox. I tried assigning the drawable to an empty string, but the compiler does not like it.

Here is the code of one of my selector states:

<item android:state_checked="true" android:drawable="">
    <shape>
        <gradient
            android:startColor="#808080"
            android:centerColor="#2F2F2F"
            android:endColor="#2F2F2F"
            android:angle="270" />
        <stroke
            android:width="2dp"
            android:color="@color/black" />
        <corners
            android:radius="5dp" />
    </shape>
</item>

解决方案

I found that I cannot remove the default radiobutton checkbox in the selector. I found that it can be removed by assigning the "button" property to null, in either the style or the definition of the radiobutton itself.

Here is an example using a style.

<RadioButton
    android:id="@+id/myRadioButton"
    style="@style/RadioButtonStyle"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/custom_radio_button"/>

<style name="RadioButtonStyle" parent="@android:style/Widget.CompoundButton">
    <item name="android:background">@drawable/radiobutton_selector</item>
    <item name="android:button">@null</item>
</style>

radiobutton_selector defines a selector that draws the button in its different checked states. Here is the checked state:

<item android:state_checked="true">
    <shape>
        <gradient
            android:startColor="@color/titleButtonCheckedGradientLight"
            android:centerColor="@color/titleButtonCheckedGradientDark"
            android:endColor="@color/titleButtonCheckedGradientDark"
            android:angle="270" />
        <stroke
            android:width="1dp"
            android:color="@color/titleButtonBorder" />
        <corners
            android:radius="5dp" />
    </shape>
</item>