【问题标题】:How to change the color of String array or String array elements如何更改字符串数组或字符串数​​组元素的颜色
【发布时间】:2023-03-20 10:03:02
【问题描述】:
    I want to change the color of each array element or whole array given bellow.so how
    can i achieve this?
            String[] title = {
                    "Abundance",
                    "Anxiety",
                    "Bruxism",
                    "Discipline",
                    "Drug Addiction"
                }
         is there any way that 
        title.setColor or 
        title[0].setColor

这将直接改变字符串值的颜色。我发现了很多,但所有答案都是字符串数组资源。

【问题讨论】:

    标签: android arrays string


    【解决方案1】:

    试试这个,

    您的字符串项目如下,

    <string-array name="menu_items" >
                <item >Abundance</item>
                <item >Anxiety</item>
                <item >Bruxism</item>
                <item >Discipline</item>
                <item >Drug Addiction</item>
    </string-array>
    
    <string-array name="menu_items_labels" >
                <item ><FONT COLOR="#006600"><b>Abundance</b></FONT></item>
                <item ><FONT COLOR="#006600"><b>Anxiety</b></FONT></item>
                <item ><FONT COLOR="#006600"><b>Bruxism</b></FONT></item>
                <item ><FONT COLOR="#006600"><b>Discipline</b></FONT></item>
                <item ><FONT COLOR="#006600"><b>Drug Addiction</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()];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-12-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多