|
| 1 | +Buffer Text Input Layout |
| 2 | +------------------------- |
| 3 | + |
| 4 | +This is a simple customisation of the TextInputLayout found in the Design Support Library. |
| 5 | + |
| 6 | +Whilst this is an awesome component that we've made great use of, we wanted to be able to display |
| 7 | +the counter so that the value displayed was: |
| 8 | + |
| 9 | +- Descending |
| 10 | +- Only visible when we reach a certain number of characters away from the maximum counter value |
| 11 | + |
| 12 | +Hence why we created this simple component :) |
| 13 | + |
| 14 | +##Ascending |
| 15 | + |
| 16 | + |
| 17 | + |
| 18 | +##Descending |
| 19 | + |
| 20 | + |
| 21 | + |
| 22 | +##Standard |
| 23 | + |
| 24 | + |
| 25 | + |
| 26 | + |
| 27 | +##Display when a given count away from the maximum value |
| 28 | + |
| 29 | + |
| 30 | + |
| 31 | + |
| 32 | +#How to use |
| 33 | + |
| 34 | +In exactly the same way as the support library! Simply wrap an edit text field like so: |
| 35 | + |
| 36 | + <org.buffer.android.buffertextinputlayout.BufferTextInputLayout |
| 37 | + android:layout_width="match_parent" |
| 38 | + android:layout_height="wrap_content" |
| 39 | + app:counterEnabled="true" |
| 40 | + app:counterMaxLength="10" |
| 41 | + app:counterOverflowTextAppearance="@style/counterOverride" |
| 42 | + app:counterTextAppearance="@style/counterText" |
| 43 | + app:hintEnabled="true" |
| 44 | + app:counterMode="ascending"> |
| 45 | + |
| 46 | + <EditText |
| 47 | + android:layout_width="match_parent" |
| 48 | + android:layout_height="wrap_content" |
| 49 | + android:hint="@string/text_hint" /> |
| 50 | + |
| 51 | + </org.buffer.android.buffertextinputlayout.BufferTextInputLayout> |
| 52 | + |
| 53 | + |
| 54 | +#Setting attributes via XML |
| 55 | + |
| 56 | +In our XML layout, we can set two extra attributes for the BufferTextInputLayout: |
| 57 | + |
| 58 | +- app:counterMode -> Set the mode in which the counter should use when being displayed (DESCENDING, ASCENDING, STANDARD) |
| 59 | +- app:displayFromCount -> Set the value for which how many characters should be remaining until the counter becomes visible |
| 60 | + |
| 61 | +e.g |
| 62 | + |
| 63 | + app:displayFromCount="5" |
| 64 | + app:counterMode="descending" |
| 65 | + |
| 66 | + |
| 67 | +#Setting attributes programmatically |
| 68 | + |
| 69 | +- setCounterMode(CounterMode counterMode) -> Set the mode in which the counter should use when being displayed (DESCENDING, ASCENDING, STANDARD) |
| 70 | +- setCharactersRemainingUntilCounterDisplay(int remainingCharacters) -> Set the value for which how many characters should be remaining until the counter becomes visible |
| 71 | + |
| 72 | +e.g. |
| 73 | + |
| 74 | + bufferTextInputLayout.setCounterMode(CounterMode.DESCENDING); |
| 75 | + bufferTextInputLayout.setCharactersRemainingUntilCounterDisplay(40); |
0 commit comments