Disable Android GridView highlighting completely (disable selection)

我的未来我决定 提交于 2019-11-29 12:22:41

问题


I'm trying to disable the highlighting of objects in a GridView in Android 2.2.

I found this other answer saying that I should set the selector to a transparent ColorDrawable (android:listSelector="@android:color/transparent"), but the views in my GridView are still dimmed when I select them.

I'm just using the GridView to display static objects in a grid. None of these objects will be selected. Would it be better to just use a basic view and draw my images manually?


回答1:


Ok, it looks like I found the answer.

In the definition of your Adapter for the GridView, you will have to override the following methods:

@Override
public boolean areAllItemsEnabled()
{
    return false;
}

@Override
public boolean isEnabled(int position)
{
    return false;
}

This will cause all of the items in your grid to be non-selectable, but it will get rid of the highlight completely.




回答2:


For keeping the items clickable you should use below attr. in your GridView xml:

android:listSelector="#00000000"

See also: https://stackoverflow.com/a/2866074/928591




回答3:


Just Set v.setOnClickListener(null);




回答4:


If you just want to disable the visual aspect of the selection, you can do the following:

gridview.getSelector().setAlpha(0);


来源:https://stackoverflow.com/questions/3159897/disable-android-gridview-highlighting-completely-disable-selection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!