2012-10-20 44 views
35

我想在我的应用程序中创建工具栏,我想知道android中工具栏的标准高度是多少?Android - 工具栏的标准高度

我希望它足够大,但手指不够大。有标准尺寸吗?

回答

31

可触摸元素的建议最小尺寸为48 dp,有关更详细的指标,请参阅this page

+31

@nrofis我建议在工具栏'android:minHeight =“?attr/actionBarSize”'的xml中设置以下内容。 –

+2

在横向模式下它不应该更小 – Zapnologica

1

您可以使用下面的方法来获得AppBar高度编程

private static final int DEFAULT_TOOLBAR_HEIGHT = 56; 

private static int toolBarHeight = -1; 

public static int getToolBarHeight(Context context) { 
     if (toolBarHeight > 0) { 
      return toolBarHeight; 
     } 
     final Resources resources = context.getResources(); 
     final int resourceId = resources.getIdentifier("action_bar_size", "dimen", "android"); 
     toolBarHeight = resourceId > 0 ? 
       resources.getDimensionPixelSize(resourceId) : 
       (int) convertDpToPixel(DEFAULT_TOOLBAR_HEIGHT); 
     return toolBarHeight; 
    } 

public static float convertDpToPixel(Context context, float dp) { 
    float scale = context.getResources().getDisplayMetrics().density; 
    return dp * scale + 0.5f; 
} 
0

对于手机它是56dp和大型设备如平板电脑你有更多的空间,它可能是64dp