2017-10-12 3 views
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); 
    } 
} 

Toutes les classes d'affichage définies dans le cadre Android étendent View. Votre vue personnalisée peut également étendre View directementCe code ne montre pas le curseur sur le champ. Je veux comprendre comment étendre correctement la classe TextInputLayoutComment étendre correctement TextInputLayout.java

+0

Vous n'avez pas ajouté phoneNumberEditText à PhoneInputLayout pour la vue enfant dans votre code. – kimkevin

Répondre

0

Je ne sais pas pourquoi vous voulez créer une vue personnalisée pour TextInputLayout. Ce qui suit fonctionne bien avec le curseur sur le champ.

<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>