An indicator that can be used as a background of person image or when it the is no image. Possibilities include every application that utilises human resources (numbers in contact apps, messages in chat applications, etc...)
1. Initials made from one pair of String
:
2. Initials made from two pairs of String
:
3. Initials made from three pairs of String
:
4. Initials made from four pairs of String
:
5. Three letter initials:
6. Customisable alpha of letters:
7. Black tinted letters:
8. Rotated letters:
Import gradle dependency:
-
Add following lines to you project's main
build.gradle
:buildscript { repositories { jcenter() } }
-
Add a dependency to application
build.gradle
:compile 'com.rzagorski:materialinitials:0.8.0'
Add MaterialInitials
view in your .xml
<com.rzagorski.materialinitials.MaterialInitials
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
or use MaterialInitialsDrawable
dynamically in your code:
MaterialInitialsDrawable drawable = new MaterialInitialsDrawable();
image.setImageDrawable(drawable);
There are three possible ways to control each aspect of drawing:
1. Use attributes in .xml
layout
2. Use methods of MaterialInitials
to control view
3. Use method of MaterialInitialsDrawable
to control Drawable
directly.
1. Initials
Initials are composed of beginning letters of words passed to it. Each String
must contain at least one word and at most 3 words.
Layout | View | Drawable |
---|---|---|
`com.rzagorski.materialinitials.MaterialInitials`
`app:mi_texts="@array/string_array"/>`
|
`String[] values;`
`miView.setTexts(values);`
|
`String[] values`
`miDrawable.setTexts(values);`
|
2. Background colors
Background colors must be the same size as texts size. The first initials will be drawn with first color background. The second initials
will be drawn with second color background, etc.
If colors are not set, the background color is taken randomly from the set of
500 material colors
Layout | View | Drawable |
---|---|---|
`com.rzagorski.materialinitials.MaterialInitials`
`app:mi_background_colors="@array/color_array"/>`
|
`int[] colors;` `miView.setBackgroundColors(colors);`
|
`int[] colors;` `miDrawable.setBackgroundColors(colors);`
|
3. Text color
This parameter specifies the rgb channels of a color used to draw initials. Must be between 0 and 255.
Layout | View | Drawable |
---|---|---|
`com.rzagorski.materialinitials.MaterialInitials`
`app:mi_text_color="@color/color"/>`
|
`int color;` `miView.setTextColor(color);`
|
`int color;` `miDrawable.setTextColor(color);`
|
4. Text alpha
This parameter specifies the alpha channel of a color used to draw initials. Must be between 0 and 255.
Layout | View | Drawable |
---|---|---|
`com.rzagorski.materialinitials.MaterialInitials`
`app:mi_textAlpha="@integer/alpha"/>`
|
`int alpha;` `miView.setTextAlpha(alpha);`
|
`int alpha;` `miDrawable.setTextAlpha(alpha);`
|
5. Text rotation
This parameter specifies the rotation of initials in clockwise direction. Must be between 0 and 360 modulo.
Layout | View | Drawable |
---|---|---|
`com.rzagorski.materialinitials.MaterialInitials`
`app:mi_rotation="@integer/rotation/>"`
|
`int rotation;` `miView.setTextRotation(rotation);`
|
`int rotation;` `miDrawable.setTextRotation(rotation);`
|
Copyright 2016 Robert Zagórski.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.