Android 如何在单击ListView行时更改放置在ListView中的视图小部件的颜色?

Android 如何在单击ListView行时更改放置在ListView中的视图小部件的颜色?,android,listview,Android,Listview,我已经生成了一个滑块列表视图。目前,我能够为所选片段高亮显示并保持高亮显示行。我还有一个视图元素,目前没有设置为任何颜色。我想在单击ListView时用橙色突出显示此视图。我该怎么做?我用来突出显示Listview行的代码如下:;请一步一步地引导我 listselector.xml <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/

我已经生成了一个滑块列表视图。目前,我能够为所选片段高亮显示并保持高亮显示行。我还有一个
视图
元素,目前没有设置为任何颜色。我想在单击ListView时用橙色突出显示此视图。我该怎么做?我用来突出显示Listview行的代码如下:;请一步一步地引导我

listselector.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/list_item_bg_normal" android:state_activated="false"/>
<item android:drawable="@drawable/list_item_bg_pressed" android:state_pressed="true"/>
<item android:drawable="@drawable/list_item_bg_pressed" android:state_activated="true"/>

</selector>

列表项已按下

   <shape xmlns:android="http://schemas.android.com/apk/res/android"android:shape="rectangle">
 <gradient
  android:startColor="@color/list_background_pressed"
  android:endColor="@color/list_background_pressed"
  android:angle="90" />
</shape>

列表\u itm\u bg\u正常

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
 <gradient
  android:startColor="@color/list_background"
  android:endColor="@color/list_background"
  android:angle="90" />
</shape>

activity_main.xml

  <ListView
    android:id="@+id/left_drawer"
     android:listSelector="@drawable/list_selector"
    android:background="@color/list_background"
    android:layout_width="240dp"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:choiceMode="singleChoice"
    android:divider="@android:color/transparent"
    android:dividerHeight="0dp"
    />

试试下面的代码,它对我有用:

   YOUR VIEW.setOnClickListener(new OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            holder.lnrMainLayout.setBackgroundResource(R.drawable.home_bg_square_selected);
                            final Timer timer = new Timer();
                            timer.schedule(new TimerTask() {

                                @Override
                                public void run() {
                                    getActivity().runOnUiThread(new Runnable() {

                                        @Override
                                        public void run() {
                                            try {
                                                holder.lnrMainLayout.setBackgroundResource(R.drawable.home_bg_square);
                                                launchActivity(obj);
                                                timer.cancel();
                                            } catch (Throwable e) {
                                                e.printStackTrace();
                                            }
                                        }
                                    });

                                }
                            }, 500, 500);

                        }
                    });

设置您想要的背景,而不是上面代码中的我的背景。

将选择器设置为所需的view@Ann检查我下面的答案,突出显示ListView行对我来说很好。@Raghunandan…thanx它可以工作