下面列出了androidx.appcompat.widget.AppCompatTextView#setId ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* 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;
}
}
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;
}
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;
}
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;
}