【问题标题】:Change color of selected words in a string更改字符串中选定单词的颜色
【发布时间】:2015-10-19 19:39:11
【问题描述】:

我正在尝试以最基本的方式在 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>"

                    };

【问题讨论】:

标签: android string button colors styles


【解决方案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);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-06-05
    • 1970-01-01
    • 2015-12-22
    • 2014-10-24
    • 1970-01-01
    • 1970-01-01
    • 2017-06-18
    • 1970-01-01
    相关资源
    最近更新 更多