목록의 각 행이 ImageView
및 두 개의 TextView
으로 구성되어 사용자 정의 된 ListView
이 있습니다. 목록의 항목을 클릭 할 때 텍스트 색상을 흰색으로 변경하고 싶습니다 (클릭 된 항목에서만). 또한 항목을 "unclicked"("언론"이 해제되었을 때)으로 검은 색으로 되돌리고 싶습니다.ListView의 텍스트 색 변경
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_selected="false"
android:state_pressed="false"
android:drawable="@color/white" />
<item android:state_pressed="true"
android:drawable="@color/red_destaques" />
<item android:state_selected="true"
android:drawable="@color/red_destaques" />
</selector>
을 그리고 listitem_row.xml
:이 다음 list_item_bg.xml
로 클릭 할 때 난 이미 항목의 배경색을 변경 한
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id="@+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="50dip"
xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="5dip"
android:maxHeight="50dip"
android:adjustViewBounds="true"
android:background="@color/list_item_bg">
<ImageView
android:layout_width="70dip"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:adjustViewBounds="true"
android:scaleType="fitStart"
android:src="@drawable/imagem_padrao_lista"
android:id="@+id/listItemLogo">
</ImageView>
<TextView
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_height="wrap_content"
android:text="TextView"
android:layout_width="wrap_content"
android:layout_toRightOf="@+id/listItemLogo"
android:layout_toLeftOf="@+id/listItemArrow"
android:textColor="#000000"
android:layout_marginLeft="5dip"
android:adjustViewBounds="true"
android:id="@+id/listItemTitle">
</TextView>
<TextView
android:layout_height="wrap_content"
android:text="TextView"
android:layout_width="wrap_content"
android:layout_toRightOf="@+id/listItemLogo"
android:layout_below="@+id/listItemTitle"
android:textColor="#333333"
android:layout_marginLeft="5dip"
android:adjustViewBounds="true"
android:id="@+id/listItemDescription">
</TextView>
<ImageView android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_alignParentRight="true" android:src="@drawable/setinha_navegacao" android:layout_centerVertical="true" android:id="@+id/listItemArrow"></ImageView>
</RelativeLayout>
내가 텍스트가 정확히 같은 방식으로 색상의 변화가 배경 위의 xml에 표시된대로 변경됩니다. 가능한 경우 코드를 변경하여이 변경 작업을 수행하는 것이 좋습니다.
=/작동하지 않습니다. 앱이 ListView를로드하려고 할 때 ANR을 수신합니다. 나는이 XML이 확실히 작동하기 때문에 텍스트 색상을 'android : textColor = "@ color/list_item_bg"'로 설정하려고 시도했지만 여전히 오류 메시지가 표시됩니다./ – Alesqui
이것을 시도하십시오. 나는 초점을 맞춘 사례를 추가했다. –
이제 완벽하게 작동합니다. 고마워요! 'TextView'를 만졌을 때 색이 바뀔 것이라고 생각했지만, 행의 어느 부분이 눌려 졌을 때 바뀌 었습니다 (예상대로). ' '의 동작 방식을 더 잘 설명하는 링크를 알고 있습니까? 피상적 인 설명 만 찾았습니다 ... –
Alesqui