html5 网站建设,家庭网络组建方案,通州重庆网站建设,wordpress部署文件总结一下设置图标的三种方式#xff1a; #xff08;1#xff09;button属性#xff1a;主要用于图标大小要求不高#xff0c;间隔要求也不高的场合。 #xff08;2#xff09;background属性#xff1a;主要用于能够以较大空间显示图标的场合。 #xff08;3#xf… 总结一下设置图标的三种方式 1button属性主要用于图标大小要求不高间隔要求也不高的场合。 2background属性主要用于能够以较大空间显示图标的场合。 3drawableLeft属性主要用于对图标与文字之间的间隔有要求的场合。 注意使用 background 或者 drawableLeft时 要设置 android:buttonnull 监听 radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { Override public void onCheckedChanged(RadioGroup group, int checkedId) { } });1234567下面是一个例子效果图 布局文件 activity_radio_button.xml 中使用 RadioGroup android:idid/radioGroup android:layout_widthmatch_parent android:layout_heightwrap_content android:layout_marginTop20dp android:orientationhorizontal RadioButton android:idid/radioButton1 android:layout_widthwrap_content android:layout_heightwrap_content android:layout_marginLeft20dp android:buttonnull android:checkedtrue android:drawablePadding10dp android:drawableTopdrawable/selback android:gravitycenter_horizontal android:text男 android:textColor#FF0033 / RadioButton android:idid/radioButton2 android:layout_widthwrap_content android:layout_heightwrap_content android:layout_marginLeft20dp android:buttonnull android:drawablePadding10dp android:drawableTopdrawable/selback android:gravitycenter_horizontal android:text女 android:textColor#000000 / /RadioGroup 123456789101112131415161718192021222324252627282930313233343536选择器selback.xml selector xmlns:androidhttp://schemas.android.com/apk/res/android item android:state_checkedtrue android:drawablemipmap/on/ item android:drawablemipmap/off//selector1234选择器用到的图片 RadioButtonActivity 中监听选中 package rolechina.jremm.com.test4; import android.app.Activity;import android.graphics.Color;import android.os.Bundle;import android.widget.RadioButton;import android.widget.RadioGroup;import android.widget.RelativeLayout;import android.widget.Toast; public class RadioButtonActivity extends Activity { private RadioGroup radioGroup; private RadioButton radioButton1; private RadioButton radioButton2; Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_radio_button); radioGroup findViewById(R.id.radioGroup); radioButton1 findViewById(R.id.radioButton1); radioButton2 findViewById(R.id.radioButton2); radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { Override public void onCheckedChanged(RadioGroup group, int checkedId) {// 选中 文字 显示红色没有选中显示黑色 if(radioButton1.isChecked()) { radioButton1.setTextColor(Color.parseColor(#FF0033)); }else{ radioButton1.setTextColor(Color.parseColor(#000000)); } if(radioButton2.isChecked()) { radioButton2.setTextColor(Color.parseColor(#FF0033)); }else{ radioButton2.setTextColor(Color.parseColor(#000000)); } } }); }} 123456789101112131415161718192021222324252627282930313233343536373839404142434445 --------------------- 转载于:https://www.cnblogs.com/hyhy904/p/10995874.html