Android 工具栏动作按钮高度
Android Toolbar Action button height
我有 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
中显示了操作按钮并按预期工作,但有一件事是操作按钮按下时突出显示不适合工具栏
有人遇到过这种问题吗?
谢谢
我不完全确定这会解决您的问题,但请尝试替换
android:layout_height="?actionBarSize"
和
android:layout_height="?android:attr/actionBarSize"
在 toolbar.xml 中。同样,不完全确定它会起作用。
应该是评论,但我太长了。
这是一个material规范。
正如您在附图中看到的那样,工具栏高度在平板电脑中为 64dp(在智能手机中为 56dp),而操作按钮高度为 48dp。
您还可以在调试菜单中检查启用的布局边距 "show layout margin"。
这里是智能手机的规格:
如果您检查样式 Widget.AppCompat.ActionButton
,您会发现 minHeight 和 minWidth 规范:
值:
<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>
我有 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
中显示了操作按钮并按预期工作,但有一件事是操作按钮按下时突出显示不适合工具栏
有人遇到过这种问题吗?
谢谢
我不完全确定这会解决您的问题,但请尝试替换
android:layout_height="?actionBarSize"
和
android:layout_height="?android:attr/actionBarSize"
在 toolbar.xml 中。同样,不完全确定它会起作用。
应该是评论,但我太长了。
这是一个material规范。
正如您在附图中看到的那样,工具栏高度在平板电脑中为 64dp(在智能手机中为 56dp),而操作按钮高度为 48dp。
您还可以在调试菜单中检查启用的布局边距 "show layout margin"。
这里是智能手机的规格:
如果您检查样式 Widget.AppCompat.ActionButton
,您会发现 minHeight 和 minWidth 规范:
值:
<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>