태그 보관물: android-checkbox

android-checkbox

CheckBox의 색상을 변경하는 방법은 무엇입니까? 기본적으로 CheckBox색상은 녹색이며이 색상을

CheckBoxAndroid 에서 기본 색상을 어떻게 변경 합니까?
기본적으로 CheckBox색상은 녹색이며이 색상을 변경하고 싶습니다.
그것이 가능하지 않다면 사용자 정의하는 방법을 알려주십시오 CheckBox.



답변

당신이 경우 minSdkVersion21+ 사용 인 android:buttonTint체크 박스의 색상을 업데이트하는 속성 :

<CheckBox
  ...
  android:buttonTint="@color/tint_color" />

AppCompat 라이브러리를 사용하고 21 미만의 Android 버전을 지원하는 프로젝트에서는 compat 버전의 buttonTint속성을 사용할 수 있습니다 .

<CheckBox
  ...
  app:buttonTint="@color/tint_color" />

이 경우 서브 클래스를 만들고 싶다면 대신 CheckBox사용 AppCompatCheckBox하는 것을 잊지 마십시오 .

이전 답변 :

속성을 CheckBox사용하여 드로어 블을 변경할 수 있습니다 android:button="@drawable/your_check_drawable".


답변

XML에서 직접 색상을 변경할 수 있습니다. buttonTint상자에 사용 : (API 레벨 23 기준)

<CheckBox
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:buttonTint="@color/CHECK_COLOR" />

appCompatCheckbox v7이전 API 레벨 에서이 작업을 수행 할 수도 있습니다.

<android.support.v7.widget.AppCompatCheckBox 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    app:buttonTint="@color/COLOR_HERE" /> 


답변

styles.xml에서 원하는 색상을 얻도록 확인란의 Android 테마를 설정할 수 있습니다.

<style name="checkBoxStyle" parent="Base.Theme.AppCompat">
    <item name="colorAccent">CHECKEDHIGHLIGHTCOLOR</item>
    <item name="android:textColorSecondary">UNCHECKEDCOLOR</item>
</style>

그런 다음 레이아웃 파일에서 :

<CheckBox
     android:theme="@style/checkBoxStyle"
     android:id="@+id/chooseItemCheckBox"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"/>

android:buttonTint="@color/CHECK_COLOR"이 방법을 사용 하는 것과 달리 Api 23에서 작동합니다.


답변

프로그래밍 버전 :

int states[][] = {{android.R.attr.state_checked}, {}};
int colors[] = {color_for_state_checked, color_for_state_normal}
CompoundButtonCompat.setButtonTintList(checkbox, new ColorStateList(states, colors));


답변

buttonTint21 개 이상의 API 버전에서 버튼 색상 및 색상 선택기를 변경하는 데 사용 합니다.

<android.support.v7.widget.AppCompatCheckBox
                android:id="@+id/check"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                app:buttonTint="@color/checkbox_filter_tint"
                tools:targetApi="21"/>

res / colors / checkbox_filter_tint.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:color="@color/light_gray_checkbox"
          android:state_checked="false"/>
    <item android:color="@color/common_red"
          android:state_checked="true"/>
</selector>


답변

내장 안드로이드 뷰를 구성하고 프로젝트에 새로운 스타일을 추가하는 방법으로 안드로이드에서 스타일 접근 방식을 사용하는 것이 좋습니다.

<style name="yourStyle" parent="Base.Theme.AppCompat">
    <item name="colorAccent">your_color</item> <!-- for uncheck state -->
    <item name="android:textColorSecondary">your color</item> <!-- for check state -->
</style>

android : theme = “@ style / youStyle”확인란의 테마에이 스타일을 추가합니다.

도움이 되었기를 바랍니다.


답변

XML에 buttonTint 추가

<CheckBox
      android:id="@+id/chk_remember_signup"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:buttonTint="@android:color/white"
      android:text="@string/hint_chk_remember_me" />