I am using Actionbar in my application.
I want the Height of the ActionBar programatically hence I am using :
ActionBar.getHeight();
But I am getting 0 value of Height.
So How can I get the Height of ActionBar?
I found the alternative of ActionBar.getHeight()
If anyone facing the same issue then this link is useful.
While @birdy's answer is an option if you want to explicitly control the ActionBar size there is a way to pull it up without locking the size that I found in support documentation. It's a little awkward but it's worked for me. You'll need a context, this example would be valid in an Activity. ~ Anthony
// Calculate ActionBar's height
TypedValue tv = new TypedValue();
if (getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data,getResources().getDisplayMetrics());
}
Below code will help too. You may need to change getContext() to this
final TypedArray styledAttributes = getContext().getTheme().obtainStyledAttributes(
new int[] { android.R.attr.actionBarSize });
mActionBarSize = (int) styledAttributes.getDimension(0, 0);
styledAttributes.recycle();
The answer is copied from this question What is the size of ActionBar in pixels?
For the newer version of Android you could simply do this:
getActionBar().getHeight()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With