AcronymAvatar is a dumb simple library to show avatars with acronyms in your application. Should you like to show user's list in your messenger (yet another one...) or just create an unorthodox user profile? This library is the best choice for you.
Just include the library into your project as a Gradle dependency:
implementation 'com.redmadrobot:acronym-avatar:2.0'
Then add AvatarView
into your XML layout:
<com.redmadrobot.acronymavatar.AvatarView
android:id="@+id/user_avatar"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
And pass full username to the setText
method:
user_avatar.setText("Captain Nemo")
That's all!
- Setting text via XML and programmatically
- Using custom placeholders (Drawables only!)
- Configuring zoom out for the acronym
Composing acronyms from text works like this: when you pass a single word through the setText
method or through the app:text
XML field, the library takes only first two symbols, and makes them an uppercased acronym. In case there are two or more words, the library takes first symbols from first and second words only, and makes them an uppercased acronym. For instance:
- Captain -> CA
- Captain Nemo -> CN
- Nemo, my name forever more -> NM
We like our default placeholder very much, but you won't probably want to use it in real-world applications ;) For this case we augmented our library with a custom placeholder feature. You can set it via XML as following:
<com.redmadrobot.acronymavatar.AvatarView
android:id="@+id/user_avatar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:placeholder="@drawable/custom_placeholder" />
The library is preconfigured to use optimal text zoom factor, but you can set your own value this way:
<com.redmadrobot.acronymavatar.AvatarView
android:id="@+id/user_avatar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:zoom_out="5" />