Ich habe eine Zeichenfolge für z. B.: "@ user mochte Ihr Foto! Vor 2 Stunden" in dünne Schrift.Ich kann nicht setSpan funktioniert
Diese Zeichenfolge besteht aus 3 Teilen;
1: -: gemocht Ihr Foto @user> es typeface.normal und klickbare
2 sein sollte! -> das bleibt gleich (dünn und schwarz)
vor 3: 2h -> das sollte grau sein.
Spannable spannedTime = new SpannableString(time);
Spannable clickableUsername = new SpannableString(username);
clickableUsername.setSpan(new StyleSpan(Typeface.NORMAL), 0, clickableUsername.length(), 0); // this is for 1st part to make it normal typeface
spannedTime.setSpan(new BackgroundColorSpan(Color.GRAY), 0, spannedTime.length(), 0); // this is for 3rd part to make it gray
clickableUsername.setSpan(new ClickableSpan() {
@Override
public void onClick(View view) {
CallProfileActivity();
}
}, 0, clickableUsername.length(), Spanned.SPAN_EXCLUSIVE_INCLUSIVE);// this is for 1st part to make it clickable
this.setText(clickableUsername + " " + notificationBody + " " + spannedTime);
Aber keiner von ihnen hat irgendwelche Auswirkungen.
Definieren Sie "nicht funktioniert" ... Was macht 'CallProfileActivity();' tun? –
siehe BackgroundColorSpan, StyleSpan und ClickableSpan, keiner von ihnen funktioniert. CallProfileActivity(); funktioniert ganz richtig, es öffnet nur eine Aktivität. –
Könnten Sie bitte ein [mcve] bereitstellen, damit wir versuchen könnten, das Problem zu reproduzieren? –