Android Toolbar Action button height

青春壹個敷衍的年華 提交于 2019-12-11 01:59:33

问题


I have res/layout/toolbar.xml which is:

<?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>

Here is my usage of 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>

I include it in any Activity Action buttons are shown and work as expected but there is one thing that action button pressed highlight does not fit toolbar

Has anyone faced this kind of problem?

Thank you


回答1:


It should be a comment, but I it is too long.

It is a material spec.

As you can see in the picture attached, the toolbar height is 64dp in tablet (56dp in smartphone), while the action button height is 48dp.

Also you can check the layout margin enabling in debug menu "show layout margin".

Source:

Here the specs for a smartphone:

If you check the style Widget.AppCompat.ActionButton you will find the minHeight and minWidth specs:

values:

 <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>

values-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>



回答2:


I'm not entirely sure this will solve your problem but try replacing

android:layout_height="?actionBarSize"

with

android:layout_height="?android:attr/actionBarSize"

in toolbar.xml. Again, not entirely sure it will work.



来源:https://stackoverflow.com/questions/30807309/android-toolbar-action-button-height

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!