Android 随机更改按钮单击时的背景色?

Android 随机更改按钮单击时的背景色?,android,Android,这是我的代码: @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_my_activity2); Button n = (Button) findViewById(R.id.button); Typeface typeface = Typeface.cr

这是我的代码:

 @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_my_activity2);
    Button n = (Button) findViewById(R.id.button);
    Typeface typeface = Typeface.createFromAsset(getAssets(), "BebasNeue Bold.ttf");
    n.setTypeface(typeface);
    final TextView tv = (TextView) findViewById(R.id.textView);
    Typeface face = Typeface.createFromAsset(getAssets(),
            "OSP-DIN.ttf");
    tv.setTypeface(face);


    final String[] values = getResources().getStringArray(R.array.things_array);
    n.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Random RAND=new Random();
            String nextValue = values[RAND.nextInt(values.length)];
            tv.setText(nextValue);
        }
    });
}
我还有这个:

<string-array name="colorcode_array">
<item>3498db</item>
<item>2ecc71</item>
<item>9b59b6</item>
<item>f1c40f</item>
<item>1abc9c</item>
<item>2980b9</item>
<item>8e44ad</item>
<item>e41c1c</item>
<item>2ecca9</item>
<item>752ecc</item>
<item>4f2ecc</item>
<item>2eccc3</item>
<item>2ecc53</item>
<item>2ecc2e</item>
<item>5bcc2e</item>
<item>9ecc2e</item>
<item>cca12e</item>
<item>cc712e</item>
<item>f1c209</item>
<item>86f109</item>
<item>f11616</item>
<item>9c1818</item>
</string-array>

3498db
2ecc71
9b59b6
f1c40f
1abc9c
2980b9
8e44ad
e41c1c
2ECA9
752ecc
4f2ecc
2eccc3
2ecc53
2ecc2e
5bcc2e
9ecc2e
cca12e
cc712e
f1c209
86f109
f11616
9c1818
现在我需要的是,在单击按钮的那一刻,您可以看到按钮已经随机地从things_数组将文本加载到textview中,但同时我希望使用colorcode_数组中的颜色代码随机更改背景颜色


我该怎么做?

查看.setBackgroundColor(Color.parseColor(“#”+array[index])应该为您完成:)


(您的案例:
view=tv
array[index]=nextValue

这会起作用,但我希望字符串数组中的所有颜色都按随机顺序排列,这正是我的意思。
string
=
“#”+array[index]
对不起,我不知道……像这样:#+colorcode\u array[index]当然,你需要用
tv
代替view,用
“#”+nextValue
代替“#”+array[index]当我点击按钮时,它崩溃了。这是因为onclick方法中的数组是things\u数组,而不是文本颜色代码,并且因为tv是textview,textview没有背景颜色吗?