2828import android .content .Context ;
2929import android .content .res .ColorStateList ;
3030import android .graphics .Typeface ;
31+ import android .os .Build .VERSION ;
3132import androidx .annotation .ColorInt ;
3233import androidx .annotation .IntDef ;
3334import androidx .annotation .NonNull ;
4243import android .view .ViewGroup .LayoutParams ;
4344import android .widget .FrameLayout ;
4445import android .widget .LinearLayout ;
45- import android .widget .Space ;
4646import android .widget .TextView ;
4747import com .google .android .material .animation .AnimationUtils ;
4848import com .google .android .material .animation .AnimatorSetCompat ;
5353
5454/**
5555 * Controller for indicator views underneath the text input line in {@link
56- * com.google.android.material.textfield.TextInputLayout}. This class controls helper and error views.
56+ * com.google.android.material.textfield.TextInputLayout}. This class controls helper and error
57+ * views.
5758 */
5859final class IndicatorViewController {
5960
@@ -371,14 +372,9 @@ void addIndicator(TextView indicator, @IndicatorIndex int index) {
371372 textInputView .addView (indicatorArea , LayoutParams .MATCH_PARENT , LayoutParams .WRAP_CONTENT );
372373
373374 captionArea = new FrameLayout (context );
374- indicatorArea .addView (
375- captionArea ,
376- -1 ,
377- new FrameLayout .LayoutParams (LayoutParams .WRAP_CONTENT , LayoutParams .WRAP_CONTENT ));
378-
379- final Space spacer = new Space (context );
380- final LayoutParams spacerLp = new LinearLayout .LayoutParams (0 , 0 , 1f );
381- indicatorArea .addView (spacer , spacerLp );
375+ LinearLayout .LayoutParams captionAreaLp =
376+ new LinearLayout .LayoutParams (0 , LayoutParams .WRAP_CONTENT , 1f );
377+ indicatorArea .addView (captionArea , captionAreaLp );
382378
383379 if (textInputView .getEditText () != null ) {
384380 adjustIndicatorPadding ();
@@ -390,7 +386,9 @@ void addIndicator(TextView indicator, @IndicatorIndex int index) {
390386 captionArea .addView (indicator );
391387 captionViewsAdded ++;
392388 } else {
393- indicatorArea .addView (indicator , index );
389+ LinearLayout .LayoutParams indicatorAreaLp =
390+ new LinearLayout .LayoutParams (LayoutParams .WRAP_CONTENT , LayoutParams .WRAP_CONTENT );
391+ indicatorArea .addView (indicator , indicatorAreaLp );
394392 }
395393 indicatorArea .setVisibility (VISIBLE );
396394 indicatorsAdded ++;
@@ -430,6 +428,9 @@ void setErrorEnabled(boolean enabled) {
430428 if (enabled ) {
431429 errorView = new AppCompatTextView (context );
432430 errorView .setId (R .id .textinput_error );
431+ if (VERSION .SDK_INT >= 17 ) {
432+ errorView .setTextAlignment (View .TEXT_ALIGNMENT_VIEW_START );
433+ }
433434 if (typeface != null ) {
434435 errorView .setTypeface (typeface );
435436 }
@@ -469,6 +470,9 @@ void setHelperTextEnabled(boolean enabled) {
469470 if (enabled ) {
470471 helperTextView = new AppCompatTextView (context );
471472 helperTextView .setId (R .id .textinput_helper_text );
473+ if (VERSION .SDK_INT >= 17 ) {
474+ helperTextView .setTextAlignment (View .TEXT_ALIGNMENT_VIEW_START );
475+ }
472476 if (typeface != null ) {
473477 helperTextView .setTypeface (typeface );
474478 }
0 commit comments