首页 > 解决方案 > android - 如何将操作栏大小放在尺寸资源文件中

问题描述

我需要在维度资源文件夹中有操作栏大小,我需要为不同的 api 版本设置不同的大小。

我已经尝试过这些代码,但后来都遇到了错误:

?android:attr/actionBarSize
?attr/actionBarSize
?actionBarSize

当我启动应用程序时,我收到此错误:

 You must supply a layout_height attribute.

如何将操作栏大小放在资源文件夹中?

标签: androidandroid-resourcesandroid-api-levels

解决方案


这对我有用:

<androidx.appcompat.widget.Toolbar
    :
    android:layout_height="?attr/actionBarSize"
    android:theme="@style/AppBarTheme" />

和:

<style name="AppBarTheme" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
    :
</style>

编辑:我也有这个:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Using the toolbar so no need to show action bar or title -->
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    :
</style>

推荐阅读