【发布时间】:2020-06-08 11:11:33
【问题描述】:
在 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"/>
【问题讨论】:
-
您是否在活动中将工具栏设置为 ActionBar?
setSupportActionbar(toolber) -
是的,我已经这样做了。
-
问题应该是
android:layout_height="match_parent"在PDFView。它覆盖了整个屏幕,包括工具栏。在 API>=21 中,由于工具栏的默认高度,它不会发生。 -
@GabrieleMariotti 非常感谢。你完全正确。如果您写此评论作为答案。我会接受的。
标签: android android-toolbar androidx android-theme android-appbarlayout