How to set a count value (badge) for a textview in android (Not for an icon or any button or any other nav items)
Image https://i.stack.imgur.com/jJcyC.png
I need to set a count value for a TextView in android. Now i have set like with hyphen in same line. But I need as a badge.
My code
private void setText(@NonNull TextView view, @StringRes int stringRes, int count) {
Utils.clear(mTextView);
view.setText(mTextiew
.append(getResources().getString(stringRes))
.append(SharedStrings.HYPHEN)
.append(count);
}
In case you like a native solution, you could look into BadgeDrawable .
Two caveats:
int
s, but this seems fine for your usecase
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.