android关于GridView动态改变背景图片的问题 你说的这个就是gridview的样式,就是写一个selector的样式,往gridview的背景放就行了 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 GridView有个属性叫android:listSelector <GridView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/grid" android:layout_width="match_parent" android:layout_height="match_parent" android:padding="10dp" android:verticalSpacing="10dp" android:horizontalSpacing="10dp" android:numColumns="auto_fit" android:columnWidth="300dip" android:stretchMode="columnWidth" android:listSelector="@drawable/grid_selector" android:gravity="center" /> <?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" android:drawable="@drawable/a" /> <item android:state_focused="false" android:drawable="@drawable/b" /> <item android:state_window_focused="true" android:drawable="@drawable/c" /> <item android:state_window_focused="false" android:drawable="@android:color/transparent" /></selector> 我也知道使用android:listSelector, 但是默认的背景色,(默认:没选中,没点击) 永远是没有的, 不起作用, 如果哪位大哥有demo,最好是现成的例子, 发给小弟, 一定会全给分,谢谢。 小弟邮箱:[email protected] 哥们啊,,我以前也遇到过,貌似默认的设置不到啊,你可以把listview背景设为蓝色,然后默认就是蓝色的了。。选中某项时item就变红,哎,仅仅是达到你说的那个效果,求高人解答啊~ 默认的怎么设置不到啊在getview里面设置自定义view,设置view的背景啊。 哥们,我很感谢你,但是你实现的效果和我的不一样, 我需要的是通过selector来控制颜色, 你没发现你的那个demo, 如果用键盘的时候, 会有focus的状态,是默认的 黄色的。。 你可能只考虑到触摸事件了 把focus状态的背景设成透明就可以了 可我要在有focus的时候就变成红色呀, 并不是点击的时候变成红色, 我是要点击的时候编程绿色。 和我的一样:gridView.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { // TODO Auto-generated method stub View selectedview = parent.getSelectedView(); selectedview.setBackgroundColor(0xf0FF7F24); if (lastselectedView != null) { lastselectedView.setBackgroundColor(0x30000000); } lastselectedView = selectedview; } @Override public void onNothingSelected(AdapterView<?> parent) { // TODO Auto-generated method stub } }); // tory test---------------------??}2,在getview中设置每一个的view背景色:mView.setBackgroundColor(0x30000000); ListView控件使用的一些问题 在onResume()中调用getIntent()得不到Extra的问题,求高手解答!!! android2.3,usb转以太网有线PPPOE拨号 求助大牛,如何添加实体键的映射? Cheapest Dofus Kamas Online apk 如何控制 屏幕背景灯?? 问个通知的问题,问题比较多 求助:Android驱动开发 WebView浏览web页面 无法记录用户浏览历史 android 持久化技术 tabhost总是抛java.lang.IllegalStateException android如何实现通话录音功能
android:id="@+id/grid"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:numColumns="auto_fit"
android:columnWidth="300dip"
android:stretchMode="columnWidth"
android:listSelector="@drawable/grid_selector"
android:gravity="center"
/>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@drawable/a" />
<item android:state_focused="false" android:drawable="@drawable/b" />
<item android:state_window_focused="true" android:drawable="@drawable/c" />
<item android:state_window_focused="false" android:drawable="@android:color/transparent" />
</selector>
哥们,我很感谢你,但是你实现的效果和我的不一样, 我需要的是通过selector来控制颜色, 你没发现你的那个demo, 如果用键盘的时候, 会有focus的状态,是默认的 黄色的。。 你可能只考虑到触摸事件了
可我要在有focus的时候就变成红色呀, 并不是点击的时候变成红色, 我是要点击的时候编程绿色。
gridView.setOnItemSelectedListener(new OnItemSelectedListener() { @Override
public void onItemSelected(AdapterView<?> parent, View view,
int position, long id) {
// TODO Auto-generated method stub
View selectedview = parent.getSelectedView();
selectedview.setBackgroundColor(0xf0FF7F24);
if (lastselectedView != null) {
lastselectedView.setBackgroundColor(0x30000000);
}
lastselectedView = selectedview;
} @Override
public void onNothingSelected(AdapterView<?> parent) {
// TODO Auto-generated method stub
}
});
// tory test---------------------??
}2,在getview中设置每一个的view背景色:
mView.setBackgroundColor(0x30000000);