Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom BiometricPrompt.Builder

Tags:

android

kotlin

Can we modify/custom ourBiometricPrompt?

For example right now i use smth like this:

BiometricPrompt.Builder(AppResources.appContext)
            .setTitle("title")
            .setSubtitle("subTitle")
            .setDescription("description")
            .setNegativeButton("Cancel", AppResources.appContext?.mainExecutor,
                    DialogInterface.OnClickListener { dialogInterface, i -> biometricCallback.onAuthenticationCancelled() })
            .build()
            .authenticate(CancellationSignal(), AppResources.appContext?.mainExecutor,
                    BiometricCallbackV28(biometricCallback))

Do I have the ability to change the style of the text, title, negativeButton color?

like image 452
Morozov Avatar asked Sep 11 '18 13:09

Morozov


2 Answers

Update2: beta01

The change with the alpha version was that the fingerprint dialog uses android.app.AlertDialog and the new beta01 uses androidx.appcompat.app.AlertDialog which has a private style.

Then to override that style we have to override androidx.appcompat.R.attr.alertDialogTheme reference in our styles.xml, we can do it replacing <item name="android:alertDialogTheme">@style/CustomAlertTheme</item> by <item name="alertDialogTheme">@style/CustomAlertTheme</item> in my case thay I only wanted to change the button text color, I just added <item name="buttonBarNegativeButtonStyle">@style/NegativeButtonStyle</item> and the same for posivtive, because replacing alertDialogTheme changes other things that I did not want to.

My styles.xml now:

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="android:textColor">@color/black</item>
        <item name="android:buttonStyle">@style/WibleButtonStyle</item>
        <item name="buttonBarNegativeButtonStyle">@style/NegativeButtonStyle</item>
 </style>

<style name="NegativeButtonStyle" parent="Widget.AppCompat.Button.ButtonBar.AlertDialog">
        <item name="android:textSize">16sp</item>
        <item name="android:textColor">@color/dark_blue</item>
</style>

Update: beta01

This trick is not working anymore. I'll try if I can find another way to do it.


I found two ways to do it, none of these are specific for the BiometricPrompt, one is to override the theme button style: <item name="android:buttonStyle">@style/CustomButtonStyle</item>

another option is to override your alert dialog theme:

AppTheme style

<item name="android:alertDialogTheme">@style/AlertDialogTheme</item>

    <style name="AlertDialogTheme" parent="ThemeOverlay.AppCompat.Dialog.Alert">
        <item name="android:buttonBarNegativeButtonStyle">@style/NegativeButtonStyle</item>
        <item name="android:buttonBarPositiveButtonStyle">@style/PositiveButtonStyle</item>
    </style>

    <style name="NegativeButtonStyle" parent="Widget.AppCompat.Button.ButtonBar.AlertDialog">
        <item name="android:textSize">10sp</item>
        <item name="android:textColor">@color/primary_text</item>
    </style>

    <style name="PositiveButtonStyle" parent="Widget.AppCompat.Button.ButtonBar.AlertDialog">
        <item name="android:textColor">@color/primary_text</item>
    </style>

And then you can apply a specific theme to a specific activity. Maybe they could open the API to allow styles, but I had to change the color because it was impossible to see the buttons (everything was white) and this is what I found to solve my problem. I hope it helps you.

like image 197
Ch4vi Avatar answered Oct 20 '22 09:10

Ch4vi


You can't set properties on the prompt that aren't exposed through its Builder - the UI is provided by the system, and is designed to be uniform throughout all apps.

This is sort of the main point of this API, this way the user becomes familiar with the prompt and knows that whatever they're interacting with is safe to use.

like image 29
zsmb13 Avatar answered Oct 20 '22 08:10

zsmb13