DImuthuUpe / AndroidPdfViewer

Android view for displaying PDFs rendered with PdfiumAndroid
Apache License 2.0
8.13k stars 1.89k forks source link

Android 10 System wide dark mode is overlapping with PDF's white background. #914

Open kayesn786 opened 4 years ago

kayesn786 commented 4 years ago

WhatsApp Image 2020-07-10 at 12 37 01 AM WhatsApp Image 2020-07-09 at 3 18 37 PM

I want the PDF to have white background. But Android 10 is forcing overlapping its dark theme with the white background. Any changes i need to do?

Here is my code

pdfView.useBestQuality(true); Constants.Cache.CACHE_SIZE = 50; pdfView.fromAsset(Constant.privacy) .enableSwipe(true) .swipeHorizontal(false) .enableDoubletap(true) .defaultPage(0). enableAnnotationRendering(false).password(null).spacing(10).onDraw(new OnDrawListener() { @Override public void onLayerDrawn(Canvas canvas, float pageWidth, float pageHeight, int displayedPage) { canvas.setDrawFilter(antialiasFilter); } }).nightMode(false) .pageFitPolicy(FitPolicy.BOTH) .scrollHandle(new DefaultScrollHandle(getContext())) .load();

Any sort of Help is appreciated. Thanks

1stmetro commented 4 years ago

Hi,

I just enabled dark mode in android 10 it doesnt effect my app it looks like it is more for the android interface,

Do you have issues with all your pdfs or just that one ?

What do you have behind the pdfview ?

kayesn786 commented 4 years ago

Hi Not all devices with android 10 has this issue. I have tested in on POCO F1 with android 10, it just works flawlessly. But when i tested it on Redmi K20 pro, i am facing this issue with all the PDF's.

I am displaying the pdf inside fragment.

here is the layout file of the same

<?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent">

<com.github.barteksc.pdfviewer.PDFView
    android:id="@+id/pdfView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

Thanks

1stmetro commented 4 years ago

Might be worth trying the spacing option and or pdfview background colour or activity background, start with the simple options first.

kayesn786 commented 4 years ago

Hi @1stmetro, I have added a white background to the to the pdfview as well as the Activity. But still the issue persists in Redmi K20 pro.

Any other changes i need to do? Thanks

kaungkhantsoe commented 4 years ago

Having the same issue as @kayesn786. Tested on Mi 9 with android 10.

kaungkhantsoe commented 4 years ago

I found a workaround for this

<com.github.barteksc.pdfviewer.PDFView android:id="@+id/pdfView" android:forceDarkAllowed="false" android:layout_width="match_parent" android:layout_height="match_parent"/>

by forcing the pdfview not to allow DarkMode. But it only works for Android 10. I haven't tested with the other android versions.

kayesn786 commented 4 years ago

@kaungkhantsoe , Thanks a lot. It worked.

deepak786 commented 3 years ago

Have the same issue https://github.com/barteksc/AndroidPdfViewer/issues/954

kayesn786 commented 3 years ago

@deepak786 the workaround specified by @kaungkhantsoe worked for me.

mariushorvat commented 3 years ago

You can add it in a new folder layout-v29 since android:forceDarkAllowed="false" only works v29 and up. One question though: Do you plan to fix this issue, eventually? while our users are constantly keep asking us why they can't view their PDFs in Darkmode.

FYI : this issue happen on all my Android 10+ devices (Samsung S10+, Google Pixel 3+, OnePlus and Sony) Thanks!