2015-08-27 3 views
2

Я хочу изменить цвет ссылки по умолчанию (textview).Как изменить цвет clickable textview в android

SpannableString ss = new SpannableString("By continuing,I agree to HCP User Agreement and Terms of Services "); 
    ClickableSpan clickableSpan = new ClickableSpan() { 
     @Override 
     public void onClick(View textView) { 
      startActivity(new Intent(UserRegister.this, ForgotPassword.class)); 
     } 
    }; 
    ss.setSpan(clickableSpan, 48, 65, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); 
    TextView textView = (TextView) findViewById(R.id.termsAndConditions); 
    textView.setText(ss); 
    textView.setMovementMethod(LinkMovementMethod.getInstance()); 
+0

'ss.setSpan (новый ForegroundColorSpan (Color.RED), 48,65, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)' – Raghunandan

+0

у меня есть код, в котором они используют wordtoSpan.setSpan (новый ForegroundColorSpan (Color.BLUE), 15, 30, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); но затем, где я должен передать объект clickablespan – Loren

+0

http://stackoverflow.com/questions/15851655/android-change-the-background-color-of-a-clickablespan-when-clicked –

ответ

0

Если вы хотите изменить TextColor всего TextView просто позвонить textView.setTextColor(R.color.text_color).

Если вы хотите раскрасить только части TextView в тексте:

final SpannableStringBuilder stringBuilder = new SpannableStringBuilder("your-string"); 
final int start = 0, end = textView.getText().length(); // Change to the start/end of the part to colorize 

// Apply some text-color 
stringBuilder.setSpan(new ForegroundColorSpan(getResources() 
    .getColor(R.color.text_color)), start, end, Spannable.SPAN_INCLUSIVE_INCLUSIVE); 

// Apply changes to TextView 
textView.setText(stringBuilder); 

Примечание: Используйте String-ресурсы, не передать строка ("By continuing,I agree to HCP User Agreement and Terms of Services " -> изменение что-то вроде getString(R.string.accept_user_agreement))

Смежные вопросы