Android 工具栏操作按钮高度

标签 android android-layout android-appcompat android-toolbar

我有 res/layout/toolbar.xml 是:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?actionBarSize"
    android:elevation="4dp"
    style="@style/ToolbarStyle">

</android.support.v7.widget.Toolbar>

这是我对工具栏的使用:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <include layout="@layout/toolbar" />


    <TextView android:text="@string/hello_world" android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</LinearLayout>

我将它包含在任何 Activity 中显示操作按钮并按预期工作,但有一件事是操作按钮按下时突出显示不适合工具栏 enter image description here

有人遇到过这种问题吗?

谢谢

最佳答案

应该是评论,但我觉得太长了。

这是一个 Material 规范

如您在附图中所见,工具栏高度在平板电脑中为 64dp(在智能手机中为 56dp),而操作按钮高度为 48dp。

您还可以在调试菜单“show layout margin”中检查启用的布局边距。

enter image description here

Source:

这里是智能手机的规范: enter image description here

如果检查样式 Widget.AppCompat.ActionButton,您会发现 minHeight 和 minWidth 规范:

值(value)观:

 <style name="Base.Widget.AppCompat.ActionButton" parent="">
       <item name="android:minWidth">@dimen/abc_action_button_min_width_material</item>
        <item name="android:minHeight">@dimen/abc_action_button_min_height_material</item>
</style>

<dimen name="abc_action_button_min_height_material">48dp</dimen>
<dimen name="abc_action_button_min_width_material">48dp</dimen>

值-v21:

<style name="Widget.Material.ActionButton" parent="Widget.ActionButton">
     <item name="minWidth">@dimen/action_button_min_width_material</item>
     <item name="minHeight">@dimen/action_button_min_height_material</item>
</style>

<dimen name="action_button_min_width_material">48dp</dimen>
<dimen name="action_button_min_height_material">48dp</dimen>

关于Android 工具栏操作按钮高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30807309/

相关文章:

android - 如何捕获运行时异常

android - 将方向设置为大屏幕的横向

android 使布局在软键盘打开时可滚动,但不向上移动

android - Lollipop 工具栏抽屉切换不可点击

android - 应该使用android :showAsAction when not using the appcompat library

android - Android 5.0 (Lollipop) 上的拆分操作栏

android - 将消息从一个 Activity 发送到另一个 Activity

android - 如何在 Android 中以编程方式从网上下载文件?

android - 样式化单选按钮 在 android 中使用 cardview

android - ActionBar AppCompat 更改 Tab 指示器颜色