1

我正在尝试构建一个具有生物特征认证(指纹)的应用程序,但我在使用否定按钮时遇到了一些问题。该按钮有效,但由于某种原因完全不可见。 这是应用程序显示的方式

这就是当你按下按钮时它看到的样子。如您所见,它存在,但我不知道如何使其可见

我在 Java 中使用 BiometricPrompt 和 BiometricManager。

编辑:似乎该按钮在不是我的任何其他手机中正常显示我使用的是小米红米 Note 8。

然而,这是我正在使用的代码:

private void initViews()
{
    biometricManager = BiometricManager.from(this);
    passwordEditText=findViewById(R.id.passwordText);
    loginButton=findViewById(R.id.loginButton);
    switch (biometricManager.canAuthenticate()) {
        case BiometricManager.BIOMETRIC_SUCCESS:
            Log.d("MY_APP_TAG", "App can authenticate using biometrics.");
            break;
        case BiometricManager.BIOMETRIC_ERROR_NO_HARDWARE:
            Log.e("MY_APP_TAG", "No biometric features available on this device.");
            break;
        case BiometricManager.BIOMETRIC_ERROR_HW_UNAVAILABLE:
            Log.e("MY_APP_TAG", "Biometric features are currently unavailable.");
            break;
        case BiometricManager.BIOMETRIC_ERROR_NONE_ENROLLED:
            Log.e("MY_APP_TAG", "The user hasn't associated " +
                    "any biometric credentials with their account.");
            break;
    }
    executor = ContextCompat.getMainExecutor(this);
    biometricPrompt = new BiometricPrompt(EnterYourPassActivity.this,
            executor, new BiometricPrompt.AuthenticationCallback() {
        @Override
        public void onAuthenticationError(int errorCode,
                                          @NonNull CharSequence errString) {
            super.onAuthenticationError(errorCode, errString);
            if(errString.equals("Use account password"))
            {
                passwordEditText.setVisibility(View.VISIBLE);
            }
            else
            {
                Log.d("MY_APP_TAG",""+errString);
                Toast.makeText(getApplicationContext(),
                        "Authentication error: " + errString, Toast.LENGTH_SHORT)
                        .show();
            }
        }

        @Override
        public void onAuthenticationSucceeded(
                @NonNull BiometricPrompt.AuthenticationResult result) {
            super.onAuthenticationSucceeded(result);
            Toast.makeText(getApplicationContext(),
                    "Authentication succeeded!", Toast.LENGTH_SHORT).show();
            Intent seeingFiles = new Intent(EnterYourPassActivity.this, SeeingFilesActivity.class);
            startActivity(seeingFiles);
        }

        @Override
        public void onAuthenticationFailed() {
            super.onAuthenticationFailed();
            Toast.makeText(getApplicationContext(), "Authentication failed",
                    Toast.LENGTH_SHORT)
                    .show();
        }
    });

    promptInfo = new BiometricPrompt.PromptInfo.Builder()
            .setTitle("Biometric login for my app")
            .setSubtitle("Log in using your biometric credential")
            .setNegativeButtonText("Use account password")
            .build();

    loginButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            biometricPrompt.authenticate(promptInfo);
        }
    });
}
4

1 回答 1

0

尝试以这种方式更改negativeButton文本:
重要- 将字符串放入资源中:

    <string name="negative_button_text"><![CDATA[<font color=\'#48a134\'>Your text at given color</font>]]></string>

如您所见,您可以设置十六进制的文本颜色。现在将negativeText放入BiometricPrompt,如下所示:

val negativeButtonText = getString(R.string.negative_button_text)
val promptInfo = BiometricPrompt.PromptInfo.Builder()
    .setTitle("title")
    .setDescription("description")
    .setNegativeButtonText(fromHtml(negativeButtonText))
    .build()

fun fromHtml(html: String): Spanned {
    return HtmlCompat.fromHtml(html, HtmlCompat.FROM_HTML_MODE_LEGACY)
}

在给定的示例中,negativeText 是绿色的,提示看起来像THIS

于 2021-10-02T21:52:24.767 回答