I have a ListView
and created a xml file for ListView
items.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/list_item_selector_back"
android:minHeight="?attr/listPreferredItemHeight"
android:orientation="vertical">
<CheckedTextView
android:id="@+id/list_item_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:checkMark="?android:attr/listChoiceIndicatorMultiple"
android:textColor="@color/list_item_selector_fore" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="@+id/list_item_author"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/list_item_selector_fore" />
<!-- and many more TextView elements -->
</LinearLayout>
</LinearLayout>
list_item_selector_fore.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@android:color/white" android:state_pressed="true" />
<item android:color="@android:color/white" android:state_activated="true" />
<item android:color="@android:color/white" android:state_focused="true" />
<item android:color="@android:color/black" />
</selector>
As you can see, I defined the background once in the root LinearLayout
. But I had to set android:textColor="@color/list_item_selector_fore"
for every TextView
.
I tried it with foreground, but nothing happened. How can I get this smarter?
HOW TO LOOK: two list view items