你说的这个就是gridview的样式,就是写一个selector的样式,往gridview的背景放就行了

解决方案 »

  1.   

    GridView有个属性叫android:listSelector
      

  2.   

      <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"
        />
      

  3.   

    <?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>
      

  4.   

    我也知道使用android:listSelector, 但是默认的背景色,(默认:没选中,没点击) 永远是没有的, 不起作用, 如果哪位大哥有demo,最好是现成的例子, 发给小弟, 一定会全给分,谢谢。  小弟邮箱:[email protected]
      

  5.   

    哥们啊,,我以前也遇到过,貌似默认的设置不到啊,你可以把listview背景设为蓝色,然后默认就是蓝色的了。。选中某项时item就变红,哎,仅仅是达到你说的那个效果,求高人解答啊~
      

  6.   

    默认的怎么设置不到啊在getview里面设置自定义view,设置view的背景啊。
      

  7.   


    哥们,我很感谢你,但是你实现的效果和我的不一样, 我需要的是通过selector来控制颜色, 你没发现你的那个demo, 如果用键盘的时候, 会有focus的状态,是默认的 黄色的。。 你可能只考虑到触摸事件了
      

  8.   

    把focus状态的背景设成透明就可以了
      

  9.   


    可我要在有focus的时候就变成红色呀, 并不是点击的时候变成红色, 我是要点击的时候编程绿色。
      

  10.   

    和我的一样:
    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);