当在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>
这里是我将pdfViewTheme应用于我的活动的AndroidManifest.xml
<activity android:name=".pdfScreen.PdfActivity" android:theme="@style/pdfViewTheme"/>
问题是android:layout_height="match_parent"
<com.github.barteksc.pdfviewer.PDFView
android:layout_height="match_parent" />
以这种方式,PDFView
覆盖了整个屏幕,包括API <21的Toolbar
。原因是AppBar/Toolbar
具有默认标高,并且位于比其他标高更高的标高上。在API <21上不起作用。