【问题标题】:Removing the onClick highlight on all items in a ListView删除 ListView 中所有项目的 onClick 突出显示
【发布时间】:2014-07-09 10:08:11
【问题描述】:

我确定这只是更改一些 xml 布局属性的问题,但我不知道是哪一个。 我有一个包含一些项目的 listView。 我正在寻找一种方法来删除单击项目时出现在项目上的蓝色突出显示背景。

【问题讨论】:

标签: android listview


【解决方案1】:

试试这个:在你的 listview xml 代码中添加这一行 android:listSelector="@android:color/transparent"

或者如果您只想更改所选项目的背景颜色将更改而其余部分将保持不变然后在您的适配器getView 方法中添加一些额外的代码

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

    if (convertView == null) {
        LayoutInflater inflater = (LayoutInflater) convertView.getContext()
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
         = inflater.inflate(
                R.layout.your_list_item, null);

    }
if(postion!=SelectedPosition)
  {
   convertView.setBackgroundColor(default Color); // change color as your wish or set transparent
    }
  else
   {
    convertView.setBackgroundColor(Color.argb(125,75,236,90));// change color as your wish or set transparent
   }



    return convertView;



}

你可以添加你自己的改变颜色的逻辑。希望有效

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-06-23
    • 2013-02-04
    • 1970-01-01
    • 1970-01-01
    • 2011-08-16
    • 2012-01-05
    • 2013-04-17
    • 1970-01-01
    相关资源
    最近更新 更多