val radiobutton: RadioButton = findViewById( R.id.home_tab) val drawable = resources.getDrawable( R.drawable.tab2_selector) drawable.setBounds(0, 0, ScreenUtil.dp2px(44), ScreenUtil.dp2px(44)) // 设置图片宽度和高度 radiobutton.setCompoundDrawables(null, drawable, null, null)
然后设置 RadioButton的背景
<shape xmlns:android="http://schemas.android.com/apk/res/android"> <padding android:top="3dp" android:bottom="3dp" /> <solid android:color="@color/white" /> </shape>
<RadioButton android:id="@+id/home_tab" style="@style/Custom.TabRadioButton" android:checked="true" android:text="" android:background="@drawable/call_bottom_tab" android:drawableTop="@drawable/tab1_selector" />
// style="@style/Custom.TabRadioButton"
<style name="Custom" />
<style name="Custom.TabRadioButton">
<item name="android:layout_width">0dp</item>
<item name="android:layout_weight">1</item>
<item name="android:layout_height">50dp</item>
<item name="android:gravity">center</item>
<item name="android:drawablePadding">0dp</item>
<item name="android:button">@null</item>
<item name="android:textSize">0sp</item>
</style>