如何通过Theme.MaterialComponents.Light缩小radioGroup中radioButton的间距

问题描述 投票:1回答:1

Theme.AppCompat.Light更改为Theme.MaterialComponents.Light之后

<style name="myRadioButtonTheme" parent="Theme.MaterialComponents.Light"> <!-- Theme.AppCompat.Light -->
        <item name="colorControlNormal">@color/radio_bt_color</item>
        <item name="colorControlActivated">@color/radio_bt_selected_color</item>
    </style>

radioGroup显示radioButton项列表的间隙更大

<RadioGroup
                android:id="@+id/fragment_radio_group"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:theme="@style/myRadioButtonTheme">


                <RadioButton
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="0dp"
                    android:text="item 1"
                    android:textColor="@color/txt_color" />

                <RadioButton
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="0dp"
                    android:text="item 2"
                    android:textColor="@color/txt_color" />

                <RadioButton
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="item3"
                    android:checked="true"
                    android:text="Choose Fantasy Sports News"
                    android:textColor="@color/txt_color" />

使用Theme.AppCompat.LightTheme.MaterialComponents.Light比较一个

enter image description here

如何减小单选按钮之间的间距?

android android-theme radio-group material-components-android
1个回答
2
投票
带有材质组件主题的RadioButton使用的默认样式是:

<style name="Widget.MaterialComponents.CompoundButton.RadioButton" parent="Widget.AppCompat.CompoundButton.RadioButton"> <item name="enforceMaterialTheme">true</item> <item name="useMaterialThemeColors">true</item> <item name="android:minWidth">?attr/minTouchTargetSize</item> <item name="android:minHeight">?attr/minTouchTargetSize</item> </style>

minTouchTargetSize属性的默认值为48dp

您可以为RadioButton使用自定义样式,也可以在布局中使用android:minHeight="xx"

© www.soinside.com 2019 - 2024. All rights reserved.