다음과 같은 버튼 모양을 적용했습니다.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<gradient android:startColor="#DD000000" android:endColor="#DD2d2d2d" android:angle="90"></gradient>
<corners android:radius="15dip"></corners>
</shape>
이제 다음과 같은 선택기를 사용하고 싶습니다.
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/active"
android:state_pressed="true" />
<item android:drawable="@drawable/passive"/>
이 버튼도 마찬가지입니다. 가능할까요 … ???
답변
이 방법으로 사용 :
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" >
<shape>.......</shape>
</item>
..........
..........
</selector>
답변
요점 답변 상세
에서 색상 리소스 만들기
res / values / colors.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<item name="yellow" type="color">#F7B500</item>
<item name="yellow_dark" type="color">#AC7E00</item>
<integer-array name="androidcolors">
<item>@color/yellow</item>
<item>@color/yellow_dark</item>
</integer-array>
</resources>
드로어 블 만들기
res / drawable / bg_yellow_round.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid android:color="@color/yellow" />
<stroke
android:width="2dp"
android:color="@color/yellow" />
<corners
android:bottomLeftRadius="20dp"
android:bottomRightRadius="20dp"
android:topLeftRadius="20dp"
android:topRightRadius="20dp" />
</shape>
다른 드로어 블을 만들고 같은 위치에서 전환하고 이름을 지정합니다.
res / drawable / bg_yellow_dark_round.xml
<solid android:color="@color/yellow_dark" />
<stroke
android:width="2dp"
android:color="@color/yellow_dark" />
<corners
android:bottomLeftRadius="20dp"
android:bottomRightRadius="20dp"
android:topLeftRadius="20dp"
android:topRightRadius="20dp" />
이제 색상 상태 목록 을
res / color / btn_selector_yellow.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" android:exitFadeDuration="@android:integer/config_shortAnimTime">
<item android:drawable="@color/yellow" android:state_focused="true" android:state_pressed="false"/>
<item android:drawable="@drawable/bg_yellow_dark_round" android:state_pressed="true"/>
<item android:drawable="@drawable/bg_yellow_round"/>
</selector>
이제 다음과 같이 버튼에 설정하십시오.
<Button
android:id="@+id/button1"
android:layout_width="248dp"
android:layout_height="44dp"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="10dp"
android:layout_marginTop="20dp"
android:background="@color/btn_selector_yellow"
android:text="AZ_ is so cool" />
지금 이것은 전환을 할 것입니다 에서
…에
.
답변
shape.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/star_off"/>
<corners android:radius="5dp"/>
<padding android:left="0dp" android:top="0dp" android:right="0dp" android:bottom="0dp" />
</shape>
selector.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android" android:exitFadeDuration="@android:integer/config_mediumAnimTime">
<item android:drawable="@color/tab_focused" android:state_focused="true" android:state_pressed="false"/>
<item android:drawable="@color/tab_pressed" android:state_pressed="true"/>
<item android:drawable="@drawable/shape"/>
</selector>
답변
내부 선택기를 사용하는 모양을 만들 수도 있습니다. 모양이 다른 상태에서 색상이 변경되는 경우 훨씬 더 깨끗합니다.
color / color_selector.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/blue_dark" android:state_pressed="true" />
<item android:color="@color/blue_light" />
</selector>
drawable / shape.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/color_selector" />
<corners android:bottomLeftRadius="6dip" android:bottomRightRadius="6dp" />
<padding android:bottom="0dip" android:left="0dip" android:right="0dip" android:top="0dip" />
</shape>
답변
너무 늦었다는 건 알지만 여기에 해결 된 예가 있습니다.
<TextView
android:id="@+id/txt_out_going_calls"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="04dp"
android:layout_weight="1"
android:background="@drawable/header_text_view_selector"
android:gravity="center"
android:text="@string/outgoing_calls_tab_button_text"
android:textColor="@color/home_text_color" />
그리고 나의 header_text_view_selector
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true">
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/home_fragment_tab_color_selected"/>
<corners android:radius="25dip" />
<padding android:bottom="08dip" android:left="9dip" android:right="9dip" android:top="08dip" />
</shape>
</item>
<item android:state_selected="false">
<shape>
<solid android:color="@color/home_fragment_tab_color_simple"/>
<corners android:radius="25dip" />
<padding android:bottom="08dip" android:left="9dip" android:right="9dip" android:top="08dip" />
</shape>
</item>
</selector>
그래서 기본적으로 textview
선택기 로 반올림 을 만듭니다 . 여기 메신저 처리 state_selected
및 not_selected
. 도움이되기를 바랍니다.
답변
이것은 내 방식이며 작동합니다!
<item android:state_pressed="true">
<shape android:shape="oval">
<gradient android:centerX=".6"
android:centerY=".40"
android:endColor="@color/colorPrimary"
android:gradientRadius="20"
android:startColor="@color/colorPrimary"
android:type="radial" />
<stroke android:width="1dp"
android:color="#FFFFFF" />
<size android:width="55dp"
android:height="55dp" />
</shape>
</item>
<item android:state_focused="false">
<shape android:shape="oval">
<gradient android:centerX=".6"
android:centerY=".40"
android:endColor="@android:color/transparent"
android:gradientRadius="20"
android:startColor="@android:color/transparent"
android:type="radial" />
<stroke android:width="1dp"
android:color="#FFFFFF" />
<size android:width="55dp"
android:height="55dp" />
</shape>
</item>
답변
이미지를 사용할 때 모양 이름을 사용하고 이미지를 사용할 때 선택기를 사용하십시오. 당신은 어떤 문제도 직면하지 않을 것입니다. 그게 당신이 요청한 것입니까?