Reputation: 647
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);
}
}
All of the view classes defined in the Android framework extend View. Your custom view can also extend View directlyThis code doesn't show the cursor on the field. I want to understand how to properly extend the TextInputLayout class
Upvotes: 0
Views: 1214
Reputation: 713
I don't know why you want to create a custom view for TextInputLayout. The following is working well with cursor on the field.
<android.support.design.widget.TextInputLayout
android:id="@+id/text_input_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:hint="Phone Number"
android:labelFor="@id/card_input_password"
android:paddingStart="12dp"
android:textColorHint="@color/text_tertiary_black"
app:errorEnabled="true"
app:hintTextAppearance="@style/TextInputLayoutFlybuysTheme">
<EditText
android:id="@id/card_input_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="top|start"
android:inputType="phone" />
</android.support.design.widget.TextInputLayout>
Upvotes: 1