안드로이드 라디오 버튼 그룹에서 라디오 버튼 아이콘을 변경할 수 있습니까?
내 안드로이드 애플리케이션 사용자가 일부 매개 변수를 설정할 수 있도록하고 싶습니다. 라디오 버튼은이 상황에 이상적입니다. 그러나 라디오 버튼이 렌더링되는 것을 좋아하지 않습니다.
라디오 버튼 아이콘을 변경할 수 있습니까? 예를 들어 각 행에 대한 사용자 지정 레이아웃을 만들고 해당 레이아웃에서 내 아이콘을 참조하고 글꼴 등을 변경할 수 있습니까?
예, res / values / styles.xml에서 라디오 버튼에 대한 고유 한 스타일을 정의해야 할 수 있습니다.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="CustomTheme" parent="android:Theme">
<item name="android:radioButtonStyle">@style/RadioButton</item>
</style>
<style name="RadioButton" parent="@android:style/Widget.CompoundButton.RadioButton">
<item name="android:button">@drawable/radio</item>
</style>
</resources>
여기서 'radio'는 상태 저장 드로어 블 (radio.xml)이어야합니다.
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:state_window_focused="false"
android:drawable="@drawable/radio_hover" />
<item android:state_checked="false" android:state_window_focused="false"
android:drawable="@drawable/radio_normal" />
<item android:state_checked="true" android:state_pressed="true"
android:drawable="@drawable/radio_active" />
<item android:state_checked="false" android:state_pressed="true"
android:drawable="@drawable/radio_active" />
<item android:state_checked="true" android:state_focused="true"
android:drawable="@drawable/radio_hover" />
<item android:state_checked="false" android:state_focused="true"
android:drawable="@drawable/radio_normal_off" />
<item android:state_checked="false" android:drawable="@drawable/radio_normal" />
<item android:state_checked="true" android:drawable="@drawable/radio_hover" />
</selector>
그런 다음 사용자 지정 테마를 전체 앱 또는 선택한 활동에 적용하면됩니다.
테마 및 스타일에 대한 자세한 내용은 http://brainflush.wordpress.com/2009/03/15/understanding-android-themes-and-styles/ 를 참조하십시오.
일반 버튼과 같이 라디오 버튼에 커스텀 이미지를 넣을 수 있습니다. 예를 들어 드로어 블 폴더에 하나의 XML 파일을 만듭니다.
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/sub_screens_aus_hl"
android:state_pressed="true"/>
<item android:drawable="@drawable/sub_screens_aus"
android:state_checked="true"/>
<item android:drawable="@drawable/sub_screens_aus"
android:state_focused="true" />
<item android:drawable="@drawable/sub_screens_aus_dis" />
</selector>
여기에서 라디오 버튼에 3 가지 다른 이미지를 사용할 수 있습니다.
이 파일을 다음과 같이 RadioButton에 사용합니다.
android:button="@drawable/aus"
android:layout_height="120dp"
android:layout_width="wrap_content"
라디오 버튼 만 변경하는 더 쉬운 방법은 드로어 블 오른쪽에 대한 선택기를 설정하는 것입니다.
<RadioButton
...
android:button="@null"
android:checked="false"
android:drawableRight="@drawable/radio_button_selector" />
그리고 선택기는 다음과 같습니다.
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/ic_checkbox_checked" android:state_checked="true" />
<item android:drawable="@drawable/ic_checkbox_unchecked" android:state_checked="false" /></selector>
그게 다야
예 ....`from Xml
android:button="@drawable/yourdrawable"
및 Java에서
myRadioButton.setButtonDrawable(resourceId or Drawable);
`
여기에 빠른 접근이 있습니다.
위에 표시된 두 개의 아이콘으로 RadioGroup
다음과 같은 것을 갖게됩니다.
RadioGroup
의 방향을 수평으로 변경- 각
RadioButton
의 속성에 대해Button
아래에 아이콘을 제공하십시오CompoundButton
. - 패딩과 크기를 조정하고
- and set the Background attribute when checked.
'program story' 카테고리의 다른 글
Qt : -lGL 오류를 찾을 수 없습니다. (0) | 2020.08.28 |
---|---|
파일에 새 줄을 추가 하시겠습니까? (0) | 2020.08.28 |
"지정된 경로의 형식은 지원되지 않습니다." (0) | 2020.08.28 |
NSAutoreleasePool 자동 릴리스 풀은 어떻게 작동합니까? (0) | 2020.08.27 |
자바 캐스팅으로 오버 헤드가 발생합니까? (0) | 2020.08.27 |