【问题标题】:Android CAB ListView background toggle issueAndroid CAB ListView 背景切换问题
【发布时间】:2012-11-28 02:39:06
【问题描述】:

我正在尝试将 CAB(上下文操作栏)添加到我的应用程序中的 ListView 中,除了一件事之外,一切都很顺利。当我最初添加 CAB 时,尽管选择了它,但当我长按它时背景颜色并没有改变。我对此的解决方案是覆盖 onItemCheckedStateChanged 并在那里设置背景颜色。我的问题是,当我尝试将背景颜色设置为之前的颜色时,我不能。 ListView 背景似乎已褪色,这意味着我无法选择与背景融为一体的颜色。你们是怎么做到的?这是我的代码:

@Override
public void onItemCheckedStateChanged(ActionMode mode, int position,
                                              long id, boolean checked) {

    if (checked) {
        //#6DCAEC is a type of Holo Blue that I want.
        listView.getChildAt(position).setBackgroundColor(Color.parseColor("#6DCAEC"));
    } else {
        //#f1f1f1 was the closest I could get to the background put it still seems out of place
        listView.getChildAt(position).setBackgroundColor(Color.parseColor("f1f1f1"));
    }
}

【问题讨论】:

  • CAB退出后要清除突出显示的项目背景吗?
  • @Singularity 是的,这就是我想要做的。

标签: android select android-actionbar cab


【解决方案1】:

试试这个代码#e7e8e9,在我的手机上试了一下,效果很好

在这里找到:Holo light color code of Navigation drawer

【讨论】:

    【解决方案2】:

    关闭ListView的选择模式:

    mListView.setChoiceMode(ListView.CHOICE_MODE_NONE);
    

    清除选择(这不会影响可见项,只是清除ListViews 内部选择列表)

    mListView.clearChoices();
    

    最后,遍历可见项并改变它们:

     for (int i = 0; i < mListView.getChildCount(); i++) {
    
            View c = mListView.getChildAt(i);
    
             //--below code is for un-checking, 
             //--you can do something else, 
             //--like altering the background
            if (c instanceof Checkable) {
                ((Checkable) c).setChecked(false);
            }
        }
    

    【讨论】:

    • 除非我调用 mListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);无法激活 CAB。我很确定你误解了我的问题。我知道如何更改背景颜色(如您在我的原始帖子中所见)。我想知道的是我应该如何改回列表视图项的原始颜色。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-26
    • 1970-01-01
    相关资源
    最近更新 更多