이미지 및 텍스트를 포함 할 수있는 버튼에 대한 맞춤 컨트롤을 개발했습니다.이를 수행 할 수있는 표준 위젯을 찾지 못했기 때문입니다. . 그것은 좋은 일하지만, 지금 내가 무엇을 실행, 그 버튼을 클릭하면, textview 그것을 누르면 상태를 변경하지 않습니다. 이 동작을 적용하여 텍스트 뷰에 ColorStateList을 적용하여 단추를 눌렀을 때 텍스트 색이 변경되도록하고 싶습니다. 이 사용자 정의 버튼의 내 XML 레이아웃은 다음과 같습니다Android : 동일한 레이아웃에서 버튼의 상태와 텍스트 뷰의 상태를 연결하는 방법
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/image_text_button"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:background="@drawable/btn_background"
android:visibility="visible"
>
<LinearLayout android:id="@+id/layoutContent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="vertical"
android:padding="3dp"
android:duplicateParentState="true">
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="2"
android:duplicateParentState="true"
android:gravity="bottom|center_horizontal"
android:src="@drawable/testing_teaser1"
/>
<TextView
android:id="@+id/textField"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:duplicateParentState="true"
android:gravity="center"
android:text="This is a ImageTextButton"
android:textColor="@color/black" />
</LinearLayout>
<Button
android:id="@+id/button"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/btn_bg_selector"
/>
</FrameLayout>
가 어떻게 버튼 상태로 텍스트 뷰를 링크 할 수 있습니다 ? 버튼이 텍스트 뷰의 부모가 아니기 때문에 android:duplicateParentState="true"
이 작동하지 않습니다.
건배 야
아주 좋은 솔루션입니다. 매력처럼 작동합니다! 그러나 Button을 'android : clickable = false'로 설정하여 클릭을 가로 채지 않도록해야했습니다. – Dude