รหัสผ่านข้อความประเภทอินพุตใน TextInputLayout

ฉันได้สร้างแบบฟอร์มในแอพ Android แล้ว มันมีลักษณะเช่นนี้ สกรีนช็อต สิ่งที่ฉันต้องการคือลักษณะที่ปรากฏของข้อความในคำแนะนำทั้งหมดที่สอดคล้องกัน ถ้าฉันใช้ inputType = "textpassword" มันจะให้ผลของการยืนยันรหัสผ่านซึ่งแตกต่างจากมุมมองอื่น (ตัวหนา) รหัสผ่านของฟิลด์มีประเภทอินพุตเดียวกัน แต่ข้อความแก้ไขไม่อยู่ใน textInputlayout รหัสสำหรับฟิลด์มีดังนี้

1>ช่องรหัสผ่าน

 <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> ยืนยันรหัสผ่าน

<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> ฟิลด์อื่น ๆ

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

สิ่งที่ฉันต้องการคือข้อความทั้งหมดให้ดูคล้ายกัน และฉันต้องการ TextInputLayout สำหรับเอฟเฟกต์ภาพเคลื่อนไหว มีวิธีทำให้ข้อความปรากฏเหมือนเดิมหรือไม่?


comment
ลองลบตระกูลแบบอักษรออกจากฟิลด์ยืนยันรหัสผ่าน เนื่องจากคุณได้ใช้แบบอักษรกับฟิลด์ข้อความแก้ไขนั้นแล้ว และเช็คอิน UI   -  person Bhavnik    schedule 08.05.2017
comment
ฉันพยายามแล้ว แต่มันไม่ทำงาน ดังที่คุณเห็นในภาพ ฟิลด์มีคำใบ้เป็นตัวหนา แต่ส่วนอื่นๆ (ขนาดตัวอักษร ฯลฯ) ดูเหมือนจะใช้ได้ หาก texinputlayout คร่อมข้อความ editext ถูกลบออก มุมมองจะทำงานตามที่คาดไว้ แต่ฉันต้องการให้วงเล็บเหลี่ยมโดย textinputlayout   -  person SarojMjn    schedule 09.05.2017


คำตอบ (4)


ลบ inputType ออกจาก editText จากไฟล์ xml และเพิ่มบรรทัดต่อไปนี้ในโค้ด java ของคุณ:

EditText registerConfirmPasswordEt = (EditText) findViewById(R.id.registerConfirmPasswordEt_text);
registerConfirmPasswordEt.setTransformationMethod(new PasswordTransformationMethod());
person R.R.M    schedule 08.05.2017
comment
ใช้งานได้เฉพาะในกรณีที่คุณไม่มี textinputlayout ที่คร่อมข้อความแก้ไข - person SarojMjn; 09.05.2017
comment
ไม่ ฉันใช้มันกับโค้ดหลายตัวที่มี textinputlayout มันทำงานได้ดี - person R.R.M; 09.05.2017
comment
ไม่ได้ทำงานสำหรับฉัน ฉันมี TextInputLayout และ TextInputEditText อยู่ข้างใน - person Azizjon Kholmatov; 03.12.2019

ฉันใส่รหัสของคุณและมันแสดงช่องยืนยันรหัสผ่านเหมือนกับช่องอื่น ๆ ... ฉันกำลังโพสต์รหัสด้านล่าง แก้ไขให้ถูกต้องหากฉันผิด (ไม่ได้ใช้ FontPath lib ในรหัสนี้)...

ภาพหน้าจอ

<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>
person Bhavnik    schedule 09.05.2017
comment
ขอบคุณสำหรับการตอบกลับ ฉันพบว่าปัญหาแตกต่างออกไปเล็กน้อย ฉันได้กล่าวถึงพวกเขาในคำตอบของฉันด้านล่าง - person SarojMjn; 09.05.2017
comment
ฉันเพิ่งโพสต์คำตอบ โปรดดู - person SarojMjn; 09.05.2017

ปัญหาไม่ได้อยู่ในการประดิษฐ์ตัวอักษรของห้องสมุด ฉันได้ลองลบมันออกแล้วใช้ Font xml* ดั้งเดิม แต่มีปัญหาเดียวกัน

ในกรณีของฉันได้รับแรงบันดาลใจจาก SarojMjn สวัสดี แก้ไขมุมมองโดยใช้วิธีนี้

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));
}

การโยกย้ายไปยังแบบอักษร xml ดั้งเดิมนั้นง่าย แต่ผลลัพธ์สุดท้ายไม่ค่อยดีนักในกรณีของฉัน โปรดดู คำถาม

person Gianluca Musa    schedule 08.02.2018

ปัญหาเกิดจากการประดิษฐ์ตัวอักษรของห้องสมุด ปัญหาข้างต้นเกิดขึ้นเมื่อคุณมีไลบรารีการประดิษฐ์ตัวอักษรและข้อความแก้ไขพร้อมรหัสผ่านข้อความประเภทอินพุตภายใน TextInputLayout วิธีแก้ปัญหาที่ฉันพบมีดังนี้

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);
person SarojMjn    schedule 09.05.2017