【问题标题】:Set color from String array to Android View background [duplicate]将字符串数组的颜色设置为Android视图背景[重复]
【发布时间】:2014-07-18 10:29:49
【问题描述】:

我有这两个数组;一个是Int类型,一个是字符串类型:

int[] COLOURS = { Color.CYAN, Color.BLUE, Color.GREEN, Color.YELLOW,
        Color.MAGENTA, Color.RED };

String[] color = { "#ff0000","#ff0f00" ,"#ffff00"};

我正在使用此代码根据进度值将整数数组中的颜色设置为视图的背景:

@Override
public void onProgressChanged(SeekBar seekBar, int progress,
        boolean fromUser) {
    full_page.setBackgroundColor(COLOURS[progress]);

}

但我需要从这个字符串数组中设置颜色:

String[] color = { "#ff0000","#ff0f00" ,"#ffff00"};

但这在我的代码中显示错误。

【问题讨论】:

    标签: android view colors


    【解决方案1】:

    喜欢

    full_page.setBackgroundColor(Color.parseColor(COLOURS[progress]));
    

    希望对你有用

    【讨论】:

      【解决方案2】:

      您必须将字符串转换为类似颜色的颜色

         Color.parseColor("#ff0000");
      

      以你的情况为例:

         Color colOne = Color.parse(color[0]);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-03-11
        • 2013-08-12
        • 1970-01-01
        • 1970-01-01
        • 2017-11-17
        • 1970-01-01
        • 2013-08-04
        • 1970-01-01
        相关资源
        最近更新 更多