【问题标题】:Android : simple_list_item_activated_1 : Listview change default blue colorAndroid : simple_list_item_activated_1 : Listview 更改默认蓝色
【发布时间】:2015-11-07 07:53:44
【问题描述】:

我正在尝试开发一个带有上一个和下一个按钮的测验应用程序。当我按下或触摸时,我可以在列表视图中突出显示所选项目。 但是当我以编程方式执行此操作时,无法使用自定义颜色突出显示该行。

问题

当我按下上一个按钮时,会运行一个查询,检查用户是否为该特定问题选择了一个选项如果是,则该位置的项目被选中并突出显示,但突出显示的颜色为 blue 。 我猜那是 app.combat.light 的主题。

我如何设置项目检查:

listviewoptions.setItemChecked(iposition, true);
//here iposition is a int variable called from db via query.

将其绑定到列表的代码

List<String> options = db.getAllOptions(QuestionID);

        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_activated_1, android.R.id.text1, options);

        listviewoptions.setAdapter(adapter);

【问题讨论】:

  • 我也尝试过使用我自己的自定义列表...但没有帮助

标签: android css listview


【解决方案1】:

到目前为止,您在程序中所做的一切都很好,但对简单列表项使用自定义布局。我相信你正在使用 android.R.layout.simple_list_item_activated_1。

创建你自己的项目布局,因为它只是一个像这样的 textView

你的.xml

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/yourselector" />

然后在drawable中定义一个选择器

yourselector.xml

<item android:state_pressed="true">
    <shape>
        <solid android:color="@color/color_slide_menu_item_pressed" />
    </shape>   
</item>

<item android:state_activated="true">
    <shape>
        <solid android:color="@color/color_slide_menu_item_activated" />
    </shape>
</item>

<item>
    <shape>
        <solid android:color="@color/color_main_theme_background" />
    </shape>
</item>

注意:定义你自己的颜色,你可以直接在那里定义它或者其他一些颜色资源

然后在你的适配器上改变布局

android.R.layout.simple_list_item_activated_1

R.layout.your

【讨论】:

    【解决方案2】:

    在您点击的列表项上,您需要调用:

    selectedItemView.setActivated(true);
    

    你的列表选择器状态drawable应该声明这个状态:

        <item android:drawable="@color/grey_07" android:state_activated="true" android:state_focused="false" android:state_pressed="false"/>
    

    【讨论】:

      猜你喜欢
      • 2012-10-26
      • 2021-03-21
      • 1970-01-01
      • 2012-01-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多