没有出现TextInputEditText错误图标

时间:2020-01-02 12:02:41

标签: android layout

我遇到了TextInputLayout PasswordToggle的问题,当我在TextInputEditText上显示错误时,红色错误图标出现在密码切换图标的顶部,因此我通过在显示错误时隐藏密码切换来解决了此问题,但现在当我单击EditText时,没有出现红色错误图标,仅出现错误消息。 谁能帮我解决这个问题?

这是我的登录屏幕

enter image description here

这是在单击“登录”按钮后

enter image description here

这是在单击TextInputEditText

之后

enter image description here

提示:如果我下次单击“登录”按钮,则会显示红色图标

这是第二次单击TextInputEditText之后

enter image description here

这是密码布局代码:

        <LinearLayout
            android:id="@+id/password_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="16dp"
            android:background="@drawable/edit_background"
            android:orientation="horizontal"
            app:layout_constraintBottom_toTopOf="@+id/btn_login"
            app:layout_constraintEnd_toEndOf="@+id/phone_layout"
            app:layout_constraintHorizontal_bias="0.5"
            app:layout_constraintStart_toStartOf="@+id/phone_layout"
            app:layout_constraintTop_toBottomOf="@+id/phone_layout">

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_margin="15dp"
                android:background="@drawable/password"
                android:contentDescription="@string/app_name"
                android:scaleType="fitXY" />

            <View
                android:layout_width="1dp"
                android:layout_height="match_parent"
                android:layout_marginTop="10dp"
                android:layout_marginBottom="10dp"
                android:background="@color/white" />

            <android.support.design.widget.TextInputLayout
                android:id="@+id/layout_user_password"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@null"
                android:gravity="start|center"
                android:textAlignment="viewStart"
                app:hintEnabled="false"
                app:passwordToggleDrawable="@drawable/hidepassword"
                app:passwordToggleEnabled="true"
                app:passwordToggleTint="@color/white"
                setPasswordVisibilityToggleEnabled="@{loginViewModel.inputValidation.isError}">

                <android.support.design.widget.TextInputEditText
                    android:id="@+id/input_user_password"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_margin="10dp"
                    android:background="@null"
                    android:gravity="start|center"
                    android:hint="@string/password_text"
                    android:inputType="textPassword"
                    android:textAlignment="viewStart"
                    android:textColor="@color/white"
                    android:textColorHint="@color/white"
                    android:text="@={loginViewModel.loginParams.password}"
                    app:error="@{loginViewModel.inputValidation.passwordError}"/>

            </android.support.design.widget.TextInputLayout>

        </LinearLayout>

1 个答案:

答案 0 :(得分:0)

与其在TextInputLayout上设置的layout_user_password上设置错误,不如说是ID为 function guessIt(){ let inputTensor = tf.browser.fromPixels(document.getElementById('imageResult'), 1)// imageResult is an <img/> tag .reshape([1, 28, 28, 1]) .cast('float32'); let predictionResult = modelJson.predict(inputTensor).dataSync(); let recognizedDigit = predictionResult.indexOf(Math.max(...predictionResult)); console.log(recognizedDigit); console.log(predictionResult); } var mousePressed = false; var lastX, lastY; var ctx; //resize image with off-screen canvas function imageToDataUri(img, width, height) { // create an off-screen canvas var canvas = document.createElement('canvas'), ctx = canvas.getContext('2d'); // set its dimension to target size canvas.width = width; canvas.height = height; // draw source image into the off-screen canvas: ctx.drawImage(img, 0, 0, width, height); // encode image to data-uri with base64 version of compressed image return canvas.toDataURL("image/png"); } function InitThis() { ctx = document.getElementById('sheet').getContext("2d"); $('#sheet').mousedown(function (e) { mousePressed = true; Draw(e.pageX - $(this).offset().left, e.pageY - $(this).offset().top, false); }); $('#sheet').mousemove(function (e) { if (mousePressed) { Draw(e.pageX - $(this).offset().left, e.pageY - $(this).offset().top, true); } }); $('#sheet').mouseup(function (e) { mousePressed = false; let img = imageToDataUri(document.getElementById("sheet"),28,28)//resize it let imgElement = document.getElementById("imageResult").setAttribute("src",img);// display it guessIt(); }); $('#sheet').mouseleave(function (e) { mousePressed = false; }); } function Draw(x, y, isDown) { if (isDown) { ctx.beginPath(); ctx.strokeStyle = "000000"; ctx.lineWidth = 9; ctx.lineJoin = "round"; ctx.moveTo(lastX, lastY); ctx.lineTo(x, y); ctx.closePath(); ctx.stroke(); } lastX = x; lastY = y; } function clearArea() { // Use the identity matrix while clearing the canvas ctx.setTransform(1, 0, 0, 1, 0, 0); ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height); document.getElementById("imageResult").setAttribute("src",""); } // init the cancas document.addEventListener('DOMContentLoaded', InitThis); 的视图。