문제

How can I make the listView like in the following ScreenShot

enter image description here

It is transparent and when press item it becomes light white.

Thanks in advance

도움이 되었습니까?

해결책

You can create a drawable file to put as the background for the listview item.

drawable/custom_background.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:drawable="@color/white" android:state_pressed="true"/>
    <item android:drawable="@color/transparent"/>

</selector>

In your styles.xml file,

<resources xmlns:android="http://schemas.android.com/apk/res/android">

    ...
    <!-- Colors -->
    <color name="white">#FFFFFFFF</color>
    <color name="transparent">#00000000</color>

</resources>

In list view adapter,

public View getView(final int position, final View convertView, final ViewGroup parent) {
    View view = convertView;
    ...
    view.setBackgroundResource(R.drawable.custom_background);
}

Just tried it. It works.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top