Android - Styling the password dialog

Hello,

I’m currently implementing a PDF viewing within an Android app. One of our requirements is that we want the activity to reflect the styling of the rest of the app (light material theme).

One thing I’ve been unable to change is the styling of is the alert dialog that pops up when trying to open a password-protected PDF. I don’t want to re-implement all the logic involved in conditionally displaying the dialog and collecting the user’s password just so I can use my own dialog with a custom style.

Any suggestions on a straightforward solution? Have I missed a theme attribute or an API call?

Thanks,

Jon

Hi Jon,

The built-in password dialog is a system AlertDialog with default styling. You could change the styling through your application manifest file. (For example: https://sites.google.com/site/androidhowto/how-to-1/customize-alertdialog-theme)

However, if you want to have custom layout, we would recommend you to create your own dialog:

if (!mPDFDoc.initStdSecurityHandler(mPassword)) {
// needs password
// show your dialog here
}

Hope this helps!

Best Regards,

Shirley Gong
Software Developer | PDFTron Systems, Inc.
sgong@pdftron.com | www.pdftron.com

Blog: blog.pdftron.com

Hi Shirley,

I have tried this approach, and unfortunately it doesn’t work. I think PDFTron might be using an AppCompatAlertDialog, which needs its styling explicitly set on its builder method (which is not-modifiable as a library consumer) . Either way it doesn’t inherit styling from the manifest.

We don’t really want to be re-implementing the password handling logic and creating our own dialog, along with all the QA effort involved. So at the moment we’re going to leave it with its default styling.

Having an easier method of styling this dialog might be a nice feature for a future release :slight_smile:

Thanks for your suggestion

Hi Jonathan,

Thanks for your feedback!

We will improve this behavior in future release!