Skip to content

Commit 1085583

Browse files
committed
[TextInputLayout] Added class documentation to use TextInputLayout's context to construct the child TextInputEditText.
We already had class documentation that explains that TextInputEditText should be instantiated with the parent TextInputLayout's context for proper theming, but this information is important enough to the basic usage of TextInputLayout and TextInputEditText that it's best to have it the class documentation, as well. Added the guidance in both TextInputLayout and TextInputEditText because it's relevant to both classes. PiperOrigin-RevId: 432244388
1 parent 2555c9b commit 1085583

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

lib/java/com/google/android/material/textfield/TextInputEditText.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@
4444
*
4545
* <p>Using this class allows us to display a hint in the IME when in 'extract' mode and provides
4646
* accessibility support for {@link com.google.android.material.textfield.TextInputLayout}.
47+
*
48+
* <p><strong>Note:</strong> If you programmatically construct a {@link TextInputEditText} as a
49+
* child of a {@link TextInputLayout}, you should use {@link TextInputLayout}'s `context` to
50+
* create the view. This will allow {@link TextInputLayout} to pass along the appropriate styling
51+
* to the {@link TextInputEditText}.
4752
*/
4853
public class TextInputEditText extends AppCompatEditText {
4954

lib/java/com/google/android/material/textfield/TextInputLayout.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@
147147
* <p>The {@link TextInputEditText} class is provided to be used as the input text child of this
148148
* layout. Using TextInputEditText instead of an EditText provides accessibility support for the
149149
* text field and allows TextInputLayout greater control over the visual aspects of the text field.
150-
* An example usage is as so:
150+
* This is an example usage:
151151
*
152152
* <pre>
153153
* &lt;com.google.android.material.textfield.TextInputLayout
@@ -169,6 +169,11 @@
169169
* TextInputLayout#setHint(CharSequence)} and {@link TextInputLayout#getHint()} on TextInputLayout,
170170
* instead of on EditText.
171171
*
172+
* If you construct the {@link TextInputEditText} child of a {@link TextInputLayout}
173+
* programmatically, you should use {@link TextInputLayout}'s `context` to create the view. This
174+
* will allow {@link TextInputLayout} to pass along the appropriate styling to the
175+
* {@link TextInputEditText}.
176+
*
172177
* <p>If the {@link EditText} child is not a {@link TextInputEditText}, make sure to set the {@link
173178
* EditText}'s {@code android:background} to {@code null} when using an outlined or filled text
174179
* field. This allows {@link TextInputLayout} to set the {@link EditText}'s background to an

0 commit comments

Comments
 (0)