Reputation: 589
I have created a form in the android app. It looks something like this. What I want is the text appearance in all the hints to be cosistent. If I use inputType = "textpassword" it gives the effect of confirm password which is different(bold) from other view. The field password has also same input type but the editext is not inside textInputlayout. The code for fields are as follows
<EditText
android:id="@+id/registerPasswordEt"
fontPath="fonts/Proxima_Nova_Light.ttf"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password *"
android:fontFamily="sans-serif"
android:textStyle="normal"
android:inputType="textPassword"
android:maxLines="1"
android:nextFocusDown="@+id/registerConfirmPasswordEt" />
2> Confirm password
<android.support.design.widget.TextInputLayout
android:id="@+id/input_layout_confirm_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/input_layout_password">
<EditText
android:id="@+id/registerConfirmPasswordEt"
fontPath="fonts/Proxima_Nova_Light.ttf"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fontFamily="sans-serif"
android:hint="Confirm Password ( must match password ) *"
android:inputType="textPassword"
android:maxLines="1"
android:nextFocusDown="@+id/registerUserNameEt"
android:textStyle="normal" />
</android.support.design.widget.TextInputLayout>
3> Other field
<android.support.design.widget.TextInputLayout
android:id="@+id/input_layout_last_name"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/registerLastNameEt"
fontPath="fonts/Proxima_Nova_Light.ttf"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Last Name *"
android:inputType="textPersonName"
android:maxLines="1"
android:nextFocusDown="@+id/registerPasswordEt" />
</android.support.design.widget.TextInputLayout>
What I want is all texts to look similar and I need TextInputLayout for animation effects. Is there a way to make the text appearance same?
Upvotes: 2
Views: 4440
Reputation: 805
The issue is not in the library calligraphy. I have try to remove it and use a native Font xml*, but have the same issue.
In my case inspired by SarojMjn hi fix the view using this method
public static void fixHintTextInputLayoutForPassword(Context context, TextInputLayout password,CharSequence text){
SpannableString spannableConfirmPasswordHint = new SpannableString(text);
spannableConfirmPasswordHint.setSpan(ResourcesCompat.getFont(context, R.font.lato_light), 0, spannableConfirmPasswordHint.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
password.setHint(spannableConfirmPasswordHint);
password.setTypeface(ResourcesCompat.getFont(context, R.font.lato_light));
}
migration to the native xml font was simple but the final result is not really good in my case, see my question
Upvotes: 1
Reputation: 589
The issue is because of the library calligraphy. Above issue occurs when you have calligraphy library and edittext with inputtype textpassword inside TextInputLayout. The solution I found are as follows.
Typeface confirmPasswordFace = Typeface.createFromAsset(getAssets(), CalligraphyConfig.get().getFontPath());
inputLayoutConfirmPassword.setTypeface(confirmPasswordFace); // or Typeface.NORMAL or any other
CalligraphyTypefaceSpan confrmPasswordTypefaceSpan = TypefaceUtils.getSpan(confirmPasswordFace);
SpannableString spannableConfirmPasswordHint = new SpannableString("Confirm Password ( must match password ) *");
spannableConfirmPasswordHint.setSpan(confrmPasswordTypefaceSpan, 0, spannableConfirmPasswordHint.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
inputLayoutConfirmPassword.setHint(spannableConfirmPasswordHint);
Upvotes: 0
Reputation: 2048
I put your code and it shows confirm password field same as other fields... I am posting code below, correct me If I am wrong (fontPath lib is not used in this code)...
<android.support.design.widget.TextInputLayout
android:id="@+id/input_layout_confirm_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/inputLayout">
<EditText
android:id="@+id/registerConfirmPasswordEt"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fontFamily="sans-serif"
android:hint="Confirm Password ( must match password ) *"
android:textColor="@color/white"
android:inputType="textPassword"
android:maxLines="1"
android:nextFocusDown="@+id/registerUserNameEt"
android:textStyle="normal" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/input_layout_last_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/inputLayout">
<EditText
android:id="@+id/registerLastNameEt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Last Name *"
android:inputType="textPersonName"
android:maxLines="1"
android:nextFocusDown="@+id/registerPasswordEt" />
</android.support.design.widget.TextInputLayout>
Upvotes: 1
Reputation: 790
Remove inputType from editText from xml file and add following line in your java code :
EditText registerConfirmPasswordEt = (EditText) findViewById(R.id.registerConfirmPasswordEt_text);
registerConfirmPasswordEt.setTransformationMethod(new PasswordTransformationMethod());
Upvotes: 2