Android ¿cómo cambiar el color de resaltado de la vista de cuadrícula?

how can change the highlight color of a imageView inside gridview.

He probado esto

 public View getView(int position, View convertView, ViewGroup parent) {

    ImageView imageView;
    if (convertView == null) {  // if it's not recycled, initialize some attributes
        imageView = new ImageView(mContext);
        imageView.setLayoutParams(new GridView.LayoutParams(width, height));
        imageView.setScaleType(ImageView.ScaleType.FIT_XY);
        imageView.setBackgroundResource(R.drawable.menu_beh);
     //   imageView.setPadding(8, 8, 8, 8);
    } else {
        imageView = (ImageView) convertView;
    }

    String s=(String)HiveApp.mgd[position].posters[2].image.url;
 //   imageView.setImageDrawable(getPicture(items[position]));
   HiveApp.id.download(s, imageView); 


  //     id.DisplayImage(s, imageView);

    return imageView;
}

preguntado el 09 de marzo de 12 a las 14:03

2 Respuestas

I resolve it my self, you shoud add this to your layout xml

 android:listSelector="@drawable/panel_picture_frame_background"

y no esto

imageView.setBackgroundResource(R.color.gridview_highlight_selector);

gracias

respondido 12 mar '12, 11:03

Worked for me too. Option above crashed. - chris barry

Añadir un imageview_highlight_selector.xml file containing the following content to the drawable folder, and then call imageView.setBackgroundResource(R.drawable.gridview_highlight_selector);.

<?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/highlight_bg" /> <!-- pressed -->
 <item android:drawable="@drawable/normal_bg" /> <!-- default -->
</selector>

I would suggest you define your gridview item in an xml file, and then inflate that xml from inside your Java code, which would be neater.

EDIT:

If you only want to use color rather a drawable, you can add a color subfolder to the res folder, and add the following content as gridview_highlight_selector.xml de las personas acusadas injustamente llamadas color folder, and call imageView.setBackgroundResource(R.color.gridview_highlight_selector); en tu código:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" android:color="#ffff" />
    <item android:color="#ff3697de" />
</selector>

respondido 09 mar '12, 16:03

Thank you for your answer, but this change the state of the background of the item, and the orange highlight don't disappear... - Vervatovskis

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.