虽然 不懂 Selector 是什么东东 ,但我知道android 的事件 分发 以及拦截。覆写 某些方法拦截事件我也不知道如何拦截 。 忘了,android 如此博大精深
解决方案 »
- httpClient发送post请求,手机通过3G上网老是超时,为什么?
- 求救啊,在代码中设置使用物理键盘的状态为关闭啊
- 求Eclipse插件能对SqliteDatabase进行操作的?
- 关于Android解析Webservice数据乱码的问题
- 求救!为什么写完的安卓程序运行时一点里面的按钮就崩溃啊?
- Android EGL_BAD_ALLOC 的问题,有没有遇到并很好的解决了?
- pull解析xml
- Android中的资源与国际化2(cl)
- 怎么用C\C++为Android写so库,写完后怎么把so加入Android上?
- android google calendar源码
- android 定时更新数据
- 如何设置AutoCompleteTextView 自动选择内容的字体大小
android:focusable="false"
android:focusableInTouchMode="false"
实在不行可以在OnItemClickListener里面进行强制修改
<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没有变色,不头痛变色
在OnItemClickListener里强制修改是怎么修改?把button的颜色变回去?
<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">如果还有更简单的方法请回复我,谢谢!
<item android:state_pressed="true"> 为 <item android:state_selected="true">修改后Button没有效果。
touch之前我就用过,不过这个不太方便。
所以我想看看能不能改好。直接使用Selector。