0
public class PhoneInputLayout extends TextInputLayout {
public void setPhoneNumberEditText(TextInputEditText
phoneNumberEditText) {
this.phoneNumberEditText = phoneNumberEditText;
}
private TextInputEditText phoneNumberEditText;
public PhoneInputLayout(Context context) {
super(context);
}
public PhoneInputLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override public void setError(@Nullable CharSequence error) {
phoneNumberEditText.setPaddingRelative(phoneNumberEditText.getPaddingStart() - getPadding(R.dimen.account_info_margin),
phoneNumberEditText.getPaddingTop(),
phoneNumberEditText.getPaddingEnd(),
phoneNumberEditText.getPaddingBottom());
super.setError(error);
}
private int getPadding(int paddingId) {
float scale = this.getContext().getResources().getDisplayMetrics().density;
return (int) (this.getContext().getResources().getDimension(paddingId) * scale + 0.5f);
}
}
Android框架中定義的所有視圖類都擴展了View。您的自定義視圖也可以擴展直接查看此代碼不顯示該字段上的光標。我想了解如何正確擴展TextInputLayout類如何正確擴展TextInputLayout.java
您沒有將phoneNumberEditText添加到PhoneInputLayout中以查看代碼中的子視圖。 – kimkevin