虽然 不懂 Selector 是什么东东 ,但我知道android 的事件 分发 以及拦截。覆写 某些方法拦截事件我也不知道如何拦截 。 忘了,android 如此博大精深

解决方案 »

  1.   

    Y你还是把demo贴出来吧,我和老八都试过没出现你说的情况。
      

  2.   

    可以尝试加入这三个属性android:clickable="false"
              android:focusable="false"
            android:focusableInTouchMode="false"
    实在不行可以在OnItemClickListener里面进行强制修改
      

  3.   

    selector_shape_btn_blue.xml<?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:state_pressed="true">
            <shape>
                <corners android:radius="3dp" />
                <solid android:color="@color/red" />
            </shape>
    </item>
        <item>
            <shape>
                <corners android:radius="3dp" />
                <solid android:color="@color/blue" />
            </shape>
    </item>
    </selector>
    selector_shape_btn_gray.xml
    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android" >
        <item android:state_pressed="true">
            <shape>
                <corners android:radius="2dip"/>
                <solid android:color="@color/gray_btn_fouce" />
            </shape>
    </item>
        <item>
    <shape>
        <corners android:radius="2dip"/>
                <solid android:color="@color/gray_btn" />
            </shape>
        </item>
    </selector> 
    main.xml
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        tools:context=".MainActivity" >
        <ListView
            android:id="@+id/lvmain"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:cacheColorHint="#00000000"
            android:descendantFocusability="blocksDescendants"
            android:listSelector="@drawable/selector_shape_btn_gray" />
    </RelativeLayout>
    item.xml
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="100dip"
        android:layout_height="match_parent"
       
        android:orientation="horizontal" >    <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/hello_world" />    <TextView
            android:id="@+id/btn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/selector_shape_btn_blue"
            android:text="aadfasfadsf" /></LinearLayout>
    点击item的时候item变色,button变色(我希望button不变色)
    点击button的时候item没有变色,不头痛变色
      

  4.   

    加属性没效果
    在OnItemClickListener里强制修改是怎么修改?把button的颜色变回去?
      

  5.   

    方法1:别用TextView,改为Button,并加上focusable
    <Button
    android:id="@+id/btn"
     android:focusable="false"
    方法2:在Adapter的getView里给btn绑定ontouchview.findViewById(R.id.btn).setOnTouchListener(new OnTouchListener() { @Override
    public boolean onTouch(View v, MotionEvent event) {
    int action = event.getAction();
    if (MotionEvent.ACTION_DOWN == action)
    v.setSelected(true);
    else if (MotionEvent.ACTION_MOVE != action)
    v.setSelected(false);
    return false;
    }
    });
    修改selector_shape_btn_blue.xml
     <item android:state_pressed="true">  为   <item android:state_selected="true">如果还有更简单的方法请回复我,谢谢!
      

  6.   

    我之前写的就是Button 我是为了试试TextView能不能用所以才改的,
     <item android:state_pressed="true">  为   <item android:state_selected="true">修改后Button没有效果。
    touch之前我就用过,不过这个不太方便。
    所以我想看看能不能改好。直接使用Selector。
      

  7.   

    可以使用了Shape改就不方便,还得单独写成xml.