Skip to content

Commit fdcdf92

Browse files
Create README.md
1 parent 848ff16 commit fdcdf92

File tree

1 file changed

+382
-0
lines changed

1 file changed

+382
-0
lines changed

README.md

Lines changed: 382 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,382 @@
1+
# TextFieldBoxes
2+
3+
4+
A new Material Design text field that comes in a box, based on [Google Material Design guidelines]
5+
6+
7+
## Installation
8+
In order to use it, you need to include it in your project.
9+
10+
#### Gradle:
11+
```groovy
12+
allprojects {
13+
repositories {
14+
...
15+
maven { url 'https://jitpack.io' }
16+
}
17+
}
18+
```
19+
```groovy
20+
dependencies {
21+
   implementation 'com.github.TutorialsAndroid:MTextField:16.4.19'
22+
}
23+
```
24+
25+
## Usage
26+
27+
#### Table of Contents
28+
1. [Basic](#basic)
29+
2. [Enable / Disable](#enable)
30+
3. [Helper Text & Error Text](#helper)
31+
4. [Prefix & Suffix](#prefix)
32+
5. [Max & Min Characters](#max)
33+
6. [Icon Signifier](#icon)
34+
7. [End Icon](#end)
35+
8. [Clear Button](#clear)
36+
9. [Custom Colors](#color)
37+
10. [Dense Spacing](#dense)
38+
11. [Always Show Hint](#hint)
39+
12. [Text Change Watcher](#watcher)
40+
13. [Dark Theme](#dark)
41+
14. [Manual Validate Error](#validate)
42+
43+
#### <a id="basic"/> 1. Basic
44+
45+
Add `com.kinda.mtextfield.TextFieldBoxes` that contains a `com.kinda.mtextfield.ExtendedEditText` to your layout:
46+
47+
```xml
48+
...
49+
<com.kinda.mtextfield.TextFieldBoxes
50+
android:id="@+id/text_field_boxes"
51+
android:layout_width="match_parent"
52+
android:layout_height="wrap_content"
53+
app:labelText="Label">
54+
55+
<com.kinda.mtextfield.ExtendedEditText
56+
android:id="@+id/extended_edit_text"
57+
android:layout_width="wrap_content"
58+
android:layout_height="wrap_content"/>
59+
60+
</com.kinda.mtextfield.TextFieldBoxes>
61+
...
62+
```
63+
64+
#### <a id="enable"/> 2. Enable / Disable
65+
66+
`app:enabled` in xml or `setEnabled(boolean enabled)` in Java.
67+
68+
```xml
69+
<com.kinda.mtextfield.TextFieldBoxes
70+
...
71+
app:enabled="false"
72+
>
73+
```
74+
75+
#### <a id="helper"/> 3. Helper Text & Error Text
76+
77+
_**NOTE:** setting helper or error text to anything **not empty** will make the bottom view (which contains the helper label) visible and increase the height of the TextFieldBoxes. So if you want to always keep the bottom view visible (height increased), set the helper text to `" "` when there should be nothing._
78+
79+
helper text: `app:helperText` in xml or `setHelperText(String helperText)` in Java.
80+
81+
```xml
82+
<com.kinda.mtextfield.TextFieldBoxes
83+
...
84+
app:helperText="Helper is here"
85+
>
86+
```
87+
88+
error text: `setError(String errorText, boolean giveFocus)` in Java.
89+
90+
Param `giveFocus` determines whether the field will gain focus when set error on. If `true`, the field gains focus immediately.
91+
92+
*NOTE: Error will be removed when the text changes (input or delete).*
93+
94+
```java
95+
setError("Error message");
96+
```
97+
98+
#### <a id="prefix"/> 4. Prefix & Suffix
99+
100+
_**! NOTE:** Prifix and Suffix attributes should be set to `ExtendedEditText`._
101+
102+
Use `app:prefix` in xml or `setPrefix(String prefix)` in Java to set the unselectable prefix text at the start of the field.
103+
104+
Use `app:suffix` in xml or `setSuffix(String suffix)` in Java to set the unselectable suffix text at the end of the field.
105+
106+
```xml
107+
<com.kinda.mtextfield.ExtendedEditText
108+
...
109+
app:prefix="$ "
110+
>
111+
```
112+
113+
```xml
114+
<com.kinda.mtextfield.ExtendedEditText
115+
...
116+
app:suffix="\@gmail.com"
117+
>
118+
```
119+
120+
#### <a id="max"/> 5. Max & Min Characters
121+
122+
_**NOTE:** setting max or min character will make the bottom view (which contains the counter label) visible and increase the height of the TextFieldBoxes._
123+
124+
Use `app:maxCharacters` in xml or `setMaxCharacters(int maxCharacters)` in java code to set the max characters count. Use `removeMaxCharacters()` in java code to remove the limit.
125+
126+
Use `app:minCharacters` in xml or `setMinCharacters(int minCharacters)` in java code to set the min characters count. Use `removeMinCharacters()` in java code to remove the limit.
127+
128+
The color of the bottom line will turn to `errorColor` (red by default) when exceeding max or min characters limit. `0`, as default, means no max or min characters limit.
129+
130+
*NOTE: Space and line feed will NOT count.*
131+
132+
```xml
133+
<com.kinda.mtextfield.TextFieldBoxes
134+
...
135+
app:maxCharacters="10"
136+
app:minCharacters="5"
137+
>
138+
```
139+
140+
```xml
141+
<com.kinda.mtextfield.TextFieldBoxes
142+
...
143+
app:maxCharacters="5"
144+
>
145+
```
146+
147+
#### <a id="icon"/> 6. Icon Signifier
148+
149+
Use `app:iconSignifier` in xml or `setIconSignifier(Int resourceID)` to set the icon that is shown in front of the TextFieldBoxes if you want there to be one.
150+
151+
You can use `setIsResponsiveIconColor(boolean isrResponsiveIconColor)` in Java code to set whether the icon will change its color when gaining or losing focus as the label text and the bottomLine do.
152+
_**NOTE that if `true`, the icon's color will always be `HighlightColor` (the same as the bottomLine) that will turn gray when losing focus. If `false`, the icon will always be in `primaryColor`.**_
153+
154+
```xml
155+
<com.kinda.mtextfield.TextFieldBoxes
156+
...
157+
app:iconSignifier="@drawable/ic_vpn_key_black_24dp"
158+
>
159+
```
160+
161+
#### <a id="end"/> 7. End Icon
162+
163+
Use `app:endIcon` in xml or `setEndIcon(Int resourceID)` to set the icon of the ImageButton that is shown at the end of the field if you want there to be one.
164+
165+
```xml
166+
<com.kinda.mtextfield.TextFieldBoxes
167+
...
168+
app:endIcon="@drawable/ic_mic_black_24dp"
169+
>
170+
```
171+
172+
To make it useful (trigger voice input, dropdown event), you would like to use `getEndIconImageButton()` in Java code to set, for example, what will happen when it's clicked (with `.setOnClickListener()`), or anything else you want.
173+
174+
```java
175+
final TextFieldBoxes textFieldBoxes = findViewById(R.id.text_field_boxes);
176+
textFieldBoxes.getEndIconImageButton().setOnClickListener(new View.OnClickListener() {
177+
@Override
178+
public void onClick(View view) {
179+
// What you want to do when it's clicked
180+
}
181+
});
182+
```
183+
184+
#### <a id="clear"/> 8. Clear Button
185+
186+
Use `app:hasClearButton` in xml or `setHasClearButton(boolean hasClearButton)` to set whether to show the clear button.
187+
188+
If `true`, a clear button will be shown at the end when there are characters (**ANY** character) entered in the field.
189+
190+
```xml
191+
<com.kinda.mtextfield.TextFieldBoxes
192+
...
193+
app:hasClearButton="true"
194+
>
195+
```
196+
197+
#### <a id="color"/> 9. Custom Colors
198+
199+
*Primary Color* will be used for the color of the underline, the floating label text and the icon signifier **when HAVING focus**. You can use `app:primaryColor` in xml or `setPrimaryColor(int colorRes)` in Java. Current theme `Primary Color` by default.
200+
201+
*Secondary Color* will be used for the color of the underline, the floating label text and the icon signifier **when NOT HAVING focus**. You can use `app:secondaryColor` in xml or `setSecondaryColor(int colorRes)` in Java. Current theme `textColorTertiary` by default.
202+
203+
*Error Color* will be used for the color that indicates error (e.g. exceeding max characters, `setError()`). You can use `app:errorColor` in xml or `setErrorColor(int colorRes)` in Java. `A400 red` by default.
204+
205+
*Helper Text Color* will be used for the color of the helper text. You can use `app:helperTextColor` in xml or `setHelperTextColor(int colorRes)` in Java. `54% black` by default.
206+
207+
*Panel Background Color* will be used for the color of panel at the back. You can use `app:panelBackgroundColor` in xml or `setPanelBackgroundColor(int colorRes)` in Java. `6% black` by default. *NOTE that the default color, as in the guideline, is the black (`#000000`) color with the transparency of 6%, so when you're customizing and want it to still be transparent you have to set a color with transparency.*
208+
209+
```xml
210+
<com.kinda.mtextfield.TextFieldBoxes
211+
...
212+
app:primaryColor="#1B5E20"
213+
app:errorColor="#ddaa00"
214+
app:helperTextColor="#795548"
215+
app:panelBackgroundColor="#ffe8e8"
216+
>
217+
```
218+
219+
*Ripple Color* will be used for the ripple effect when the view is clicked. You can customize it in your `styles.xml` by adding the following:
220+
221+
```xml
222+
<style name="TextFieldBoxes">
223+
<item name="android:colorControlHighlight" tools:targetApi="lollipop">YOUR_COLOR</item>
224+
</style>
225+
```
226+
227+
then set this as the theme for your TextFieldBoxes:
228+
```xml
229+
<com.kinda.mtextfield.TextFieldBoxes
230+
...
231+
android:theme="@style/TextFieldBoxes"
232+
>
233+
```
234+
235+
#### <a id="dense"/> 10. Dense Spacing
236+
237+
You can make the layout compact by using a dense verticle spacing to improve user experience in some cases.
238+
239+
Use `app:useDenseSpacing` in xml or `setUseDenseSpacing(boolean useDenseSpacing)` to set whether the field uses a dense spacing between its elements.
240+
241+
```xml
242+
<com.kinda.mtextfield.TextFieldBoxes
243+
...
244+
app:useDenseSpacing="true"
245+
>
246+
```
247+
248+
#### <a id="hint"/> 11. Always Show Hint
249+
250+
Sometimes you may want the label and the hint to show different messages, but need the hint to always be shown (instead being blocked by the label when losing focus).
251+
252+
Use `app:alwaysShowHint` in xml or `setAlwaysShowHint(boolean alwaysShowHint)` to set whether the label is fixed at top when there's a hint in the EditText.
253+
254+
```xml
255+
<com.kinda.mtextfield.TextFieldBoxes
256+
...
257+
app:alwaysShowHint="true"
258+
>
259+
```
260+
261+
#### <a id="watcher"/> 12. Text Change Watcher
262+
263+
It is strongly recommanded to use `setSimpleTextChangeWatcher()` to listen the event of changing text instead of `addTextChangedListener()`.
264+
265+
This has the following advantages:
266+
1. You don't need to implement `beforeTextChanged()` and `onTextChanged()` method when unnecessary.
267+
2. Avoids potential unexpected behavior, by guaranteeing your code to run after the default processes (remove error, update counter text, etc.) are finished.
268+
3. When the view is recycled, no manual remove call is needed.
269+
270+
e.g.
271+
```java
272+
final TextFieldBoxes textFieldBoxes = findViewById(R.id.text_field_boxes);
273+
textFieldBoxes.setSimpleTextChangeWatcher(new SimpleTextChangedWatcher() {
274+
@Override
275+
public void onTextChanged(String theNewText, boolean isError) {
276+
// What you want to do when text changes
277+
}
278+
});
279+
```
280+
281+
#### <a id="dark"/> 13. Dark Theme
282+
283+
TextFieldBoxes use the color attributes within the current theme and will automatically change its color to fit the dark theme without additional settings.
284+
285+
#### <a id="validate"/> 14. Manual Validate Error
286+
287+
By default, the error state of the field is validated each time the text changes and also at time of construction. This means a field with a minimum length requirement will start in the Error state.
288+
289+
Setting `app:manualValidateError` to `true` will make the field validate error only when `validate()` is called.
290+
291+
```xml
292+
<com.kinda.mtextfield.TextFieldBoxes
293+
...
294+
app:manualValidateError="true"
295+
>
296+
```
297+
```Java
298+
final TextFieldBoxes textFieldBoxes = findViewById(R.id.text_field_boxes);
299+
// The error state will only be updated when this is called
300+
textFieldBoxes.validate()
301+
```
302+
303+
## All Attributes
304+
305+
### ExtendedEditText
306+
307+
##### Texts
308+
309+
| Attribute | Description |
310+
| --- | --- |
311+
| `app:prefix` | Prefix Text |
312+
| `app:suffix` | Suffix Text |
313+
314+
##### Colors
315+
316+
| Attribute | Description | Default |
317+
| --- | --- | --- |
318+
| `app:prefixTextColor` | Prefix text color | Current theme `textColorTertiary` |
319+
| `app:suffixTextColor` | Suffix text color | Current theme `textColorTertiary` |
320+
321+
### TextFieldBoxes
322+
323+
##### Texts
324+
325+
| Attribute | Description |
326+
| --- | --- |
327+
| `app:labelText` | Floating label text at the top |
328+
| `app:helperText` | Helper text at the bottom |
329+
330+
##### Colors
331+
332+
| Attribute | Description | Default |
333+
| --- | --- | --- |
334+
| `app:helperTextColor` | Helper text color | Current theme `textColorTertiary` |
335+
| `app:counterTextColor` | Counter text color | Current theme `textColorTertiary` |
336+
| `app:errorColor` | The color that is used to indicate error (e.g. exceeding max characters, `setError()`) | `A400 red` |
337+
| `app:primaryColor` | The color for the underline, the floating label text and the icon signifier **when HAVING FOCUS** | Current theme `colorPrimary` |
338+
| `app:secondaryColor` | The color for the underline, the floating label text and the icon signifier **when NOT HAVING FOCUS** | Current theme `textColorTertiary` |
339+
| `app:panelBackgroundColor` | The color for the panel at the back | 6% Current theme `colorForeground` |
340+
341+
##### Icons
342+
343+
| Attribute | Description | Default |
344+
| --- | --- | --- |
345+
| `app:iconSignifier` | The resource ID of the icon before the TextFieldBoxes | `0` |
346+
| `app:endIcon` | The resource ID of the icon at the end of the field | `0` |
347+
| `app:isResponsiveIconColor` | whether the icon signifier will change its color when gaining or losing focus as the label and the bottomLine do | `True` |
348+
349+
##### Characters counter
350+
351+
| Attribute | Description | Default |
352+
| --- | --- | --- |
353+
| `app:maxCharacters` | Max characters count limit. `0` means no limit | `0` |
354+
| `app:minCharacters` | Min characters count limit. `0` means no limit | `0` |
355+
356+
##### Others
357+
358+
| Attribute | Description | Default |
359+
| --- | --- | --- |
360+
| `app:enabled` | Whether the text field is enabled | `True` |
361+
| `app:hasClearButton` | Whether to show the clear button at the end of the EditText | `False` |
362+
| `app:hasFocus` | Whether the EditText is having the focus | `False` |
363+
| `app:alwaysShowHint` | Whether the label is fixed at top when there's a hint in the EditText | `False` |
364+
| `app:useDenseSpacing` | Whether the field uses a dense spacing between its elements | `False` |
365+
| `app:manualValidateError` | Whether to validate error state only when `validate()` is called | `False` |
366+
367+
368+
## License
369+
370+
Copyright 2019 MTextField
371+
372+
Licensed under the Apache License, Version 2.0 (the "License");
373+
you may not use this file except in compliance with the License.
374+
You may obtain a copy of the License at
375+
376+
http://www.apache.org/licenses/LICENSE-2.0
377+
378+
Unless required by applicable law or agreed to in writing, software
379+
distributed under the License is distributed on an "AS IS" BASIS,
380+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
381+
See the License for the specific language governing permissions and
382+
limitations under the License.

0 commit comments

Comments
 (0)