【问题标题】:how to change the color of string array resources in android如何在android中更改字符串数组资源的颜色
【发布时间】:2014-10-14 12:07:11
【问题描述】:

这是我的 menu_items.xml,其元素显示在列表视图中。它们默认为黑色。我希望它们是白色的。如何更改这些字符串数组项的颜色? 下面是我的 menu_items.xml 代码。

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string-array name="menu_items" >
        <item >Demo Mode</item>
        <item >Inbox</item>
        <item >Sent Items</item>
        <item >Filing History</item>
    </string-array>
</resources>   

【问题讨论】:

  • 您想在哪里更改它们?在 IDE 中还是在您的应用中?
  • 在我的应用程序中,它们显示在列表视图中,即我希望它们显示为白色。

标签: android resources arrays


【解决方案1】:

将您的字符串项设置为:

   <string-array name="menu_items" >
        <item >Demo Mode</item>
        <item >Inbox</item>
        <item >Sent Items</item>
        <item >Filing History</item>
    </string-array>

   <string-array name="menu_items_labels" >
        <item ><FONT COLOR="#006600"><b>Demo Mode</b></FONT></item>
        <item ><FONT COLOR="#006600"><b>Inbox</b></FONT></item>
        <item ><FONT COLOR="#006600"><b>Sent Items</b></FONT></item>
        <item ><FONT COLOR="#006600"><b>Filing History</b></FONT></item>
      </string-array>

在您的微调器代码中 - 使用:

// For setting the html code "menu_items_labels" with font color white
Spinner spinner = (Spinner) findViewById(R.id.my_spinner);
spinner.setAdapter(
      new ArrayAdapter<CharSequence>(this, 
         R.layout.multiline_spinner_dropdown_item, 
        myActivity.this.getResources().getTextArray(R.array.menu_items_labels)));

要检索字符串值(没有 HTML 格式),

strTemp = getResources().getStringArray(R.array.menu_items)[spinner.getSelectedItemPosition()];

【讨论】:

    【解决方案2】:

    您不能直接告诉(数组)资源它应该具有哪种颜色。您可以定义应用程序范围的主题/样式以用于列表项,也可以使用自定义视图创建适配器,在您的情况下,ArrayAdapter 最适合。

    Hot to create an ArrayAdapter with a custom view.

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-20
      • 1970-01-01
      • 2014-09-28
      • 1970-01-01
      相关资源
      最近更新 更多