You can simply do it by this way:
<android.support.design.widget.TextInputLayout
android:id="@+id/phone_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Phone Number">
<android.support.design.widget.TextInputEditText
android:id="@+id/phone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="+6281342134"
android:inputType="phone"/>
</android.support.design.widget.TextInputLayout>
But this will result overlapping of both hints i.e. Phone Number and +6281342134. So you need to implement OnFocusChangeListener
for this. (Not so good solution but it'll work for you).
In your layout, add hint to TextInputLayout
only. I have set hintAnimationEnabled
to false
because I think the animation might won't look smooth with different hints.
<android.support.design.widget.TextInputLayout
android:id="@+id/phone_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Phone Number"
app:hintAnimationEnabled="false">
<android.support.design.widget.TextInputEditText
android:id="@+id/phone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="phone"/>
</android.support.design.widget.TextInputLayout>
In your java file, create OnFocusChangeListener
:
private View.OnFocusChangeListener onPhoneNumberFocusChangeListener = new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
((EditText)v).setHint("+6281342134");
} else {
((EditText)v).setHint("");
}
}
};
and set it to your EditText
phone.setOnFocusChangeListener(onPhoneNumberFocusChangeListener);