나는 안드로이드에 원형 모양으로 확인란을 만드는 문제에 직면하고있다. 많은 방법을 시도했지만 내 문제가 해결되지 않았습니다. 도형을 만들고 확인란에 적용하면 문제가 해결되지 않습니다. 원형 모양으로 확인란을 만드는 방법을 알려주세요. checkBox를 원형으로 만드는 방법은 무엇입니까?
그림과 같은 원형 확인란을 만드는 방법.
나는 안드로이드에 원형 모양으로 확인란을 만드는 문제에 직면하고있다. 많은 방법을 시도했지만 내 문제가 해결되지 않았습니다. 도형을 만들고 확인란에 적용하면 문제가 해결되지 않습니다. 원형 모양으로 확인란을 만드는 방법을 알려주세요. checkBox를 원형으로 만드는 방법은 무엇입니까?
그림과 같은 원형 확인란을 만드는 방법.
시간을 보낸 후에 사용할 수있는이 템플릿을 만들었습니다. 필요에 따라을 수정해야 할 수도 있습니다. activity.xml
<CheckBox
android:id="@+id/checkb"
android:layout_width="115dp"
android:layout_height="50dp"
android:button="@drawable/custom_checkbox"
android:scaleX="3"
android:scaleY="3"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginRight="15dp"
android:layout_marginEnd="15dp" />
에서
작성
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true">
<layer-list>
<item>
<shape android:shape="oval">
<corners android:radius="1dp" />
<stroke
android:width="1dp"
android:color="#777" />
<gradient
android:startColor="#990000"
android:centerColor="#990000"
android:endColor="#990000"
android:angle="270" />
<size
android:width="30dp"
android:height="30dp" />
</shape>
</item>
<item
android:width="8dp"
android:height="2dp"
android:top="20dp"
android:left="6dp">
<rotate
android:fromDegrees="45">
<shape android:shape="rectangle">
<solid android:color="#fff"/>
</shape>
</rotate>
</item>
<item
android:width="19dp"
android:height="2dp"
android:top="16dp"
android:left="9dp">
<rotate
android:fromDegrees="-45">
<shape android:shape="rectangle">
<solid android:color="#fff"/>
</shape>
</rotate>
</item>
</layer-list>
</item>
</selector>
checked.xml라는 당김 폴더에 새 XML을
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_checked="true"
android:drawable="@drawable/checked" />
<item android:state_pressed="true"
android:drawable="@drawable/checked" />
<item android:state_pressed="false"
android:drawable="@drawable/unchecked" />
</selector>
custom_checkbox.xml라는 당김 폴더에 새 XML을 생성
unchecked.xml이라는 드로어 블 폴더에 새 xml을 만듭니다
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval">
<corners android:radius="1dp" />
<stroke
android:width="1dp"
android:color="#777" />
<gradient
android:startColor="#990000"
android:centerColor="#990000"
android:endColor="#990000"
android:angle="270" />
<size
android:width="30dp"
android:height="30dp" />
</shape>
선택하지 않으면 다음과 같이 표시됩니다.
이 때 아래와 같이
을 보이는 것 확인 (당신은 checked.xml에서 사이에 코드를 추가하고 상단을 수정하고 확인란을 선택하지 않은 경우 X를 제공하기 위해 남아 수)이것이 작동하는 경우 대답으로 표시하십시오.
해결 방법은 정확하지만 동일한 흐름에 따라 모양이 변형되어 "checked.xml"에 드로어 블을 사용할 수 있습니다.이 솔루션은 모양이 너비 나 높이가 없기 때문에이 솔루션은 API 21 이전의 Android 장치에서 작동합니다. xml 드로어 블.
검사되지 않은 XML :
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval">
<solid android:color = "@color/lightgray" />
</shape>
검사 XML :
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android = "http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<solid android:color="@color/colorPrimary" />
</shape>
</item>
<item
android:drawable="@drawable/check_arrow_png" />
</layer-list>
또한 체크 화살표의 벡터 이미지는 안드로이드 벡터 확인입니다. 재료 디자인 스타일의 확인란이 있어야합니다. –
[비슷한 질문] http://stackoverflow.com/questions/38798168/customized-circular-checkbox-in - 안드로이드 이걸 해봤 니? – chirag90
시도했지만 문제가 해결되지 않았습니다 –
http://android-dev-examples.blogspot.co.uk/2014/09/android-custom-checkbox.html이 튜토리얼은 어떻게됩니까? 내려 앉으면 맞춤 체크 박스 버튼과 배경이 표시됩니다 원 버튼 – chirag90