Android Material Design:如何设置工具栏操作按钮的触摸目标大小?

时间:2015-05-24 19:16:29

标签: android

阅读本节

http://www.google.com/design/spec/layout/metrics-keylines.html#metrics-keylines-touch-target-size

所以在我的工具栏中我有按钮

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools" tools:context=".MainActivity">
    <item android:id="@+id/action_settings" android:title="@string/action_settings"
        android:orderInCategory="100" app:showAsAction="never" />

    <item android:id="@+id/info" android:title="info"
        android:icon="@android:drawable/ic_dialog_info"
        android:orderInCategory="200" app:showAsAction="always" />

    <item android:id="@+id/map" android:title="map"
        android:icon="@android:drawable/ic_dialog_map"
        android:orderInCategory="300" app:showAsAction="always" />
</menu>

如何设置触摸目标尺寸?所有这些动作按钮必须是48乘48 dp

但据我了解动作按钮的尺寸

  1. 18x18(MDPI)
  2. 24x24(HDPI)
  3. 36x36(XDPI)
  4. 48x48(XXHDPI)
  5. 那么如何为MDPI图像设置48dp触摸目标大小?

    请帮忙

1 个答案:

答案 0 :(得分:0)

ImageView making it clickable.

The Image is 18 x 18 dp.

The view is 48 x 48

Finding the padding. (48 - 18) / 2 = padding

<ImageView
    style="?android:buttonBarButtonStyle"
    android:layout_width="48dp"
    android:layout_height="48dp"
    android:clickable="true"
    android:padding="15dp"
    android:src="@mipmap/ic_launcher"/>