können Sie einstellen, benutzerdefinierte Schriftart und Farben mit spannable.
Try this:
protected void setActionBarTitle(String title) {
//if API level below 18, there is a bug at Samsung and LG devices
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) {
getSupportActionBar().setTitle(title);
} else {
SpannableString s = new SpannableString(title);
s.setSpan(new TypefaceSpan(this, "Your-Font.ttf"), 0, s.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
s.setSpan(new ForegroundColorSpan(ContextCompat.getColor(getApplicationContext(), R.color.colorAccent)), 0, s.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
getSupportActionBar().setTitle(s);
}
}
In Ihrem Fall das funktionieren sollte:
SpannableString firstPart = new SpannableString("Videos ");
SpannableString lastPart = new SpannableString(" (4)");
firstPart.setSpan(new ForegroundColorSpan(ContextCompat.getColor(getApplicationContext(), R.color.white)), 0, firstPart.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
lastPart.setSpan(new ForegroundColorSpan(ContextCompat.getColor(getApplicationContext(), R.color.black)), 0, lastPart.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
dann stellen Sie Ihren Titel thike dies:
getSupportActionBar().setTitle(firstPart + lastPart);
oder wie folgt aus:
getSupportActionBar().setTitle(TextUtils.concat(firstPart, lastPart));
Dies erklärt nicht, wie mehrere Farben in einem einzigen Toolbar-Titel verwendet werden. Ich möchte auch nicht die Schriftart ändern. – user486123
@ user486123 Zuerst sagte ich dir die Logik dahinter. Just updated meine Antwort/ –
Hatte 'TextUtils.concat (firstPart, lastPart)' anstelle von 'firstPart + lastPart' zu verwenden, aber danke! – user486123