5
하나의 목록보기가 있습니다. 어댑터의 getView() 메소드에서 다음과 같이 대체 행 색상을 할당했습니다.Listview 대체 행 색상 및 선택한 항목 배경색을 설정하는 방법
if(position % 2 ==1)
{
convertView.setBackgroundColor(Color.rgb(231, 249, 255));
}
else
{
convertView.setBackgroundColor(Color.rgb(195, 240, 255));
}
위 코드는 정상적으로 작동합니다. 이제 선택한 목록 항목의 색을 변경하고 싶습니다. 나는 다음과 같은 listSelector의 XML을 생성 한
: 그 동안 나는 아래의 절차를 따랐다
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Selected -->
<item
android:state_focused="true"
android:state_selected="false"
android:drawable="@drawable/focused"/>
<!-- Pressed -->
<item
android:state_selected="true"
android:state_focused="false"
android:drawable="@drawable/selected" />
</selector>
을 나는 다음과 같이 내 목록에 위의 선택기를 할당 :
myList.setSelector(R.drawable.list_selector);
그러나 선택한 목록 항목 색상이 표시되지 않습니다.
누구나 안드로이드 목록에 대체 행 색상과 선택한 목록 항목 색상을 설정하는 방법을 알려주십시오.
[여기는 않음] [1] [1] : http://stackoverflow.com/questions/21249981/how-to-change-custom-listview-row-color-change-alternatively/21250701? noredirect = 1 # 21250701 행 색상 변경에 도움이 될 수 있습니다. –