Android导航栏大小在xml中

有没有什么办法可以在android的xml文件中得到类似于这个导航栏的大小?

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

其中actionBarSize是导航栏大小?

在Android的源代码看起来像导航栏高度的维度:

 @android:dimen/navigation_bar_height 

还有其他维度链接到导航栏,从android值/ dimens.xml的例子:

 <!-- Height of the bottom navigation / system bar. --> <dimen name="navigation_bar_height">48dp</dimen> <!-- Height of the bottom navigation bar in portrait; often the same as @dimen/navigation_bar_height --> <dimen name="navigation_bar_height_landscape">48dp</dimen> <!-- Width of the navigation bar when it is placed vertically on the screen --> <dimen name="navigation_bar_width">42dp</dimen> 

试试这个代码 :

 Resources resources = context.getResources(); int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android"); if (resourceId > 0) { return resources.getDimensionPixelSize(resourceId); } return 0;