0

I am trying to write questions and answers in android studio in the most basic of ways. My plan is to have the answer in white (the color of the background currently)...then when the answer button is hit it'll change the entire thing to black. So how do you have the that Answer span a different color to start?

    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>"

                    };
pjhollow
  • 85
  • 1
  • 6
  • It's probably easier to just use two TextViews and make one invisible at first. – Karakuri Jul 29 '15 at 02:27
  • you can use spans from the following link, http://stackoverflow.com/questions/11479560/custom-textview-in-android-with-different-color-words – Reprator Jul 29 '15 at 02:54

1 Answers1

1

You can use Spannable to achieve this.

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);
Antrromet
  • 15,294
  • 10
  • 60
  • 75