I'm implementing a custom view inside the Android action bar. The problem is that under some conditions I need to double the height of the action bar to allow the view to be displayed completely. I can set the height using a custom theme, but this height is static.
Is is possible to change the action bar height programmatically?
Under your in-game Video Options, check the "Use UI Scale" option and adjust it to the right accordingly. That will increase the UI size (including your action bars).
You can set the height here android:minHeight="? attr/actionBarSize" in your XML. Use height and not minHeight.
We can see that we are able to fetch the ActionBar height, which is equal to 147 Pixels.
All action buttons and other items available in the action overflow are defined in an XML menu resource. To add actions to the action bar, create a new XML file in your project's res/menu/ directory. The app:showAsAction attribute specifies whether the action should be shown as a button on the app bar.
You can do this using reflection (possibly not a good idea):
Window window = getWindow();
View v = window.getDecorView();
int actionBarId = getResources().getIdentifier("action_bar", "id", "android");
ViewGroup actionBarView = (ViewGroup) v.findViewById(actionBarId);
try {
Field f = actionBarView.getClass().getSuperclass().getDeclaredField("mContentHeight");
f.setAccessible(true);
f.set(actionBarView, 50);
} catch (NoSuchFieldException e) {
} catch (IllegalAccessException e) {
}
RyanCheu's answer worked for me, but I found that if I selected text in an activity, the text selection toolbar appeared at the default action bar size, which resized the activity, which removed the text selection, so it was impossible to use the Copy and Select All functions. I ended up going back to using themes to set the action bar height, and changing themes programmatically using setTheme() and recreate(). Example code is here:
https://stackoverflow.com/a/37974527/462162
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