【问题标题】:how to reduce the gap for radioButton in radioGroup with Theme.MaterialComponents.Light如何使用 Theme.MaterialComponents.Light 减少 radioGroup 中 radioButton 的间隙
【发布时间】:2020-02-13 18:07:45
【问题描述】:

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 比较一个

如何减少单选按钮之间的间隙?

【问题讨论】:

    标签: android android-theme radio-group material-components-android


    【解决方案1】:

    带有 Material Components Theme 的 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"

    【讨论】:

      猜你喜欢
      • 2013-08-03
      • 1970-01-01
      • 2021-02-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多