我有兩個按鈕,男性和女性,我想要做的是,如果用戶選擇一個男性按鈕,更改背景顏色,它作爲一個RadioGroup的方式,只需選擇男性或女性。如何創建兩個按鈕的狀態android
<LinearLayout
android:paddingTop="20dp"
android:layout_gravity="center"
android:weightSum="2"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:id="@+id/btn_male"
android:textColor="@color/White"
android:background="@color/colorPrimaryDark"
android:layout_gravity="end"
android:text="@string/male"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="genderPerson"
/>
<Button
android:id="@+id/btn_female"
android:textColor="@color/White"
android:background="@color/colorPrimaryDark"
android:text="@string/female"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="genderPerson"
/>
</LinearLayout>
所以使用RadioGroup中 –