質問

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