【问题标题】:How to set padding for radio button in Android如何在Android中为单选按钮设置填充
【发布时间】:2021-04-08 05:04:44
【问题描述】:

我使用的是默认单选按钮,没有进行任何自定义。我想在按钮图标的左侧添加填充。我试过 padding-left,但它只是改变图标和文本之间的空间。

我知道它可以通过使用drawable left并将按钮设置为null来轻松实现,但它可能会丢失动画和默认样式。

我的代码

              <com.google.android.material.radiobutton.MaterialRadioButton
                android:id="@+id/rb_bank"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@drawable/bg_payment_method"
                android:buttonTint="@color/colorPrimaryDark"
                android:padding="15dp"
                android:text="@string/bank"
                android:textColor="@color/textColorSecondary"
                android:textSize="16sp" />

电流输出

【问题讨论】:

    标签: android radio-button material-components-android


    【解决方案1】:

    您可以将材质按钮包装在 LinearLayout 中,将背景 android:background="@drawable/bg_payment_method" 设置为 LinearLayout 并给出 margin_left radioButton

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/bg_payment_method" >
        <com.google.android.material.radiobutton.MaterialRadioButton
            android:id="@+id/rb_bank"
            android:layout_marginLeft="40dp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:buttonTint="@color/colorPrimaryDark"
            android:text="@string/bank"
            android:textColor="@color/textColorSecondary"
            android:textSize="16sp" />
    </LinearLayout>
    

    【讨论】:

      猜你喜欢
      • 2013-09-06
      • 1970-01-01
      • 2011-05-07
      • 1970-01-01
      • 2013-05-01
      • 1970-01-01
      • 2012-04-21
      • 2015-10-11
      • 2012-02-21
      相关资源
      最近更新 更多