What's the height of the Android Toolbar?

后端 未结 2 410
盖世英雄少女心
盖世英雄少女心 2020-12-08 04:27

What is the height of the Android Toolbar introduced in Lollipop? It\'s a quite simple question but I haven\'t found an answer here except for the ActionB

相关标签:
2条回答
  • 2020-12-08 05:07

    Call this method to get the value programmatically:

    public int getToolBarHeight() {
        int[] attrs = new int[] {R.attr.actionBarSize};
        TypedArray ta = getContext().obtainStyledAttributes(attrs);
        int toolBarHeight = ta.getDimensionPixelSize(0, -1);
        ta.recycle();
        return toolBarHeight;
    }
    
    0 讨论(0)
  • 2020-12-08 05:10

    The Toolbar (if not extended) has the height of:

    • 56dp (default)
    • 48dp (landscape)
    • 64dp (sw600dp; i.e. tablet)

    The Toolbar is higher than the pre-lollipop ActionBar; it was 48dp by default, 40dp in landscape and 56dp in sw600dp.

    And to retrieve the height of the Toolbar in XML, just use

    ?android:attr/actionBarSize

    or if you're using the AppCompat library this

    ?attr/actionBarSize

    0 讨论(0)
提交回复
热议问题