Java Code Examples for androidx.appcompat.widget.AppCompatTextView#setId()

The following examples show how to use androidx.appcompat.widget.AppCompatTextView#setId() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TextInputLayout.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
/**
 * Whether the character counter functionality is enabled or not in this layout.
 *
 * @attr ref com.google.android.material.R.styleable#TextInputLayout_counterEnabled
 */
public void setCounterEnabled(boolean enabled) {
  if (counterEnabled != enabled) {
    if (enabled) {
      counterView = new AppCompatTextView(getContext());
      counterView.setId(R.id.textinput_counter);
      if (typeface != null) {
        counterView.setTypeface(typeface);
      }
      counterView.setMaxLines(1);
      indicatorViewController.addIndicator(counterView, COUNTER_INDEX);
      MarginLayoutParamsCompat.setMarginStart(
          (MarginLayoutParams) counterView.getLayoutParams(),
          getResources().getDimensionPixelOffset(R.dimen.mtrl_textinput_counter_margin_start));
      updateCounterTextAppearanceAndColor();
      updateCounter();
    } else {
      indicatorViewController.removeIndicator(counterView, COUNTER_INDEX);
      counterView = null;
    }
    counterEnabled = enabled;
  }
}
 
Example 2
Source File: TextInputLayout.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
private void setPlaceholderTextEnabled(boolean placeholderEnabled) {
  // If the enabled state is the same as before, do nothing.
  if (this.placeholderEnabled == placeholderEnabled) {
    return;
  }

  // Otherwise, adjust enabled state.
  if (placeholderEnabled) {
    placeholderTextView = new AppCompatTextView(getContext());
    placeholderTextView.setId(R.id.textinput_placeholder);

    ViewCompat.setAccessibilityLiveRegion(
        placeholderTextView, ViewCompat.ACCESSIBILITY_LIVE_REGION_POLITE);

    setPlaceholderTextAppearance(placeholderTextAppearance);
    setPlaceholderTextColor(placeholderTextColor);
    addPlaceholderTextView();
  } else {
    removePlaceholderTextView();
    placeholderTextView = null;
  }
  this.placeholderEnabled = placeholderEnabled;
}
 
Example 3
Source File: IndicatorViewController.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
void setErrorEnabled(boolean enabled) {
  // If the enabled state is the same as before, do nothing.
  if (errorEnabled == enabled) {
    return;
  }

  // Otherwise, adjust enabled state.
  cancelCaptionAnimator();

  if (enabled) {
    errorView = new AppCompatTextView(context);
    errorView.setId(R.id.textinput_error);
    if (VERSION.SDK_INT >= 17) {
      errorView.setTextAlignment(View.TEXT_ALIGNMENT_VIEW_START);
    }
    if (typeface != null) {
      errorView.setTypeface(typeface);
    }
    setErrorTextAppearance(errorTextAppearance);
    setErrorViewTextColor(errorViewTextColor);
    setErrorContentDescription(errorViewContentDescription);
    errorView.setVisibility(View.INVISIBLE);
    ViewCompat.setAccessibilityLiveRegion(errorView, ViewCompat.ACCESSIBILITY_LIVE_REGION_POLITE);
    addIndicator(errorView, ERROR_INDEX);
  } else {
    hideError();
    removeIndicator(errorView, ERROR_INDEX);
    errorView = null;
    textInputView.updateEditTextBackground();
    textInputView.updateTextInputBoxState();
  }
  errorEnabled = enabled;
}
 
Example 4
Source File: IndicatorViewController.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
void setHelperTextEnabled(boolean enabled) {
  // If the enabled state is the same as before, do nothing.
  if (helperTextEnabled == enabled) {
    return;
  }

  // Otherwise, adjust enabled state.
  cancelCaptionAnimator();

  if (enabled) {
    helperTextView = new AppCompatTextView(context);
    helperTextView.setId(R.id.textinput_helper_text);
    if (VERSION.SDK_INT >= 17) {
      helperTextView.setTextAlignment(View.TEXT_ALIGNMENT_VIEW_START);
    }
    if (typeface != null) {
      helperTextView.setTypeface(typeface);
    }
    helperTextView.setVisibility(View.INVISIBLE);
    ViewCompat.setAccessibilityLiveRegion(
        helperTextView, ViewCompat.ACCESSIBILITY_LIVE_REGION_POLITE);
    setHelperTextAppearance(helperTextTextAppearance);
    setHelperTextViewTextColor(helperTextViewTextColor);
    addIndicator(helperTextView, HELPER_INDEX);
  } else {
    hideHelperText();
    removeIndicator(helperTextView, HELPER_INDEX);
    helperTextView = null;
    textInputView.updateEditTextBackground();
    textInputView.updateTextInputBoxState();
  }
  helperTextEnabled = enabled;
}