我试图以最基本的方式在android studio中编写问题和答案。我的计划是将答案设为白色(当前背景的颜色)......然后当按下答案按钮时,它会将整个事物改为黑色。那么你如何让答案跨越不同的颜色呢?
Button button = (Button) findViewById(R.id.questionButton);
button.setOnClickListener(
new Button.OnClickListener() {
public void onClick(View v) {
final String[] Text = {
"Q: Who is the first president of the United States? <COLOR SOMETHING TO MAKE THIS WHITE TEXT-> >A: George Washington</COLOR>"
};
答案 0 :(得分:1)
您可以使用Spannable来实现此目标。
String text = "Q: Who is the first president of the United States? <font color='white'>A: George Washington</font>";
textView.setText(Html.fromHtml(text), TextView.BufferType.SPANNABLE);