How to get Spannable and its color from TextView to write a unit test

后端 未结 1 1662
别那么骄傲
别那么骄傲 2021-02-14 15:06
private void createStringEndingInRedColor(TextView tv, String word1, String word2) {
    Spannable word = new SpannableString(word1);
    tv.setText(word);

    Spannabl         


        
1条回答
  •  深忆病人
    2021-02-14 15:32

    You can get the color of the Spannable from TextView using getSpans() method

    ForegroundColorSpan[] colorSpans = ((SpannableString)textView.getText()).getSpans(0, textView.getText().length(), ForegroundColorSpan.class);
    assertTrue(colorSpans[0].getForegroundColor() == Color.RED)
    

    0 讨论(0)
提交回复
热议问题