在API 21以下运行时,工具栏未显示。当前,我在API 19模拟器中运行此应用程序。此相同的布局在运行API 21及以上版本的设备上正常工作。
以下是翻译的结果:
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".pdfScreen.PdfActivity">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.appcompat.widget.Toolbar
android:id="@+id/pdf_activity_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize">
</androidx.appcompat.widget.Toolbar>
</com.google.android.material.appbar.AppBarLayout>
<com.github.barteksc.pdfviewer.PDFView
android:id="@+id/pdfView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<include
android:id="@+id/include_pdf_menu"
layout="@layout/pdf_activity_bottom_menu"/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</layout>
以下是翻译的结果:
这是style.xml文件
<style name="themeForApp" parent="Theme.AppCompat.Light.NoActionBar">
Customize your theme here.
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:textColor">@color/textOnPrimary</item>
</style>
<style name="pdfViewTheme" parent="themeForApp.NoActionBar">
</style>
这是 v21/style.xml
文件。
<style name="themeForApp" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:statusBarColor">@android:color/transparent</item>
</style>
<style name="pdfViewTheme" parent="themeForApp">
<item name="android:windowFullscreen">true</item>
</style>
这里是我的AndroidManifest.xml
文件,我在其中将pdfViewTheme应用于我的活动
<activity android:name=".pdfScreen.PdfActivity" android:theme="@style/pdfViewTheme"/>
setSupportActionbar(toolber)
- ArrowsomePDFView
中的android:layout_height="match_parent"
。它覆盖了整个屏幕,包括工具栏。在API>=21中,由于工具栏的默认高度,这种情况不会发生。 - Gabriele Mariotti