Determine if action bar is split

自闭症网瘾萝莉.ら 提交于 2019-12-30 08:18:07

问题


I have a MapView with an action bar powered by ActionBarSherlock. The action bar is both split (on "narrow" screens) and overlayed / semi-transparent (android:windowActionBarOverlay is true). More or less like the Google Maps app.

Now I would like to push views on top of the map, at the bottom of the screen still keeping it above the bottom action bar. My problem here is that I don't know the height of the bottom action bar. Frankly, I can't even find a way to know if it's drawn or not. getHeight() seems to return the height of the top action bar (or perhaps it's the height of both of them but I still don't know if the bottom action bar exists or not.

Please, tell me this information is right in front of my eyes!


回答1:


If you are using ActionBarSherlock you can look for the boolean value abs__split_action_bar_is_narrow

Just create some static method where you can do

return ResourcesCompat.getResources_getBoolean(context,
                            R.bool.abs__split_action_bar_is_narrow);

you need to use the ResourcesCompat (from actionbarsherlock) class because pre 3.2 cant read folders with metrics (like values-sw480)




回答2:


I ran into the same problem. On phone devices in portrait mode the actionbar is split. So menu-items are in the top actionbar and the tabs in a second actionbar (tabbar) below. I just did not find any possible way to determine the height of the actionbar: to see what space is left on the screen before building my screen.

So I did an assumption:

  • on small and normal screensize devices the actionbar is split in portrait mode
  • on large screensize devices (like Nexus 7) the actionbar is also split in portrait mode
  • on xlarge screensize devices (tablets) the actionbar is not split in portrait mode

So I distinguish the different screensizes and created a bool resource

<!-- res/values/booleans.xml -->
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <bool name="is_split_actionbar">false</bool>
</resources>

<!-- res/values-small-port/booleans.xml
     res/values-normal-port/booleans.xml
     res/values-large-port/booleans.xml -->
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <bool name="is_split_actionbar">true</bool>
</resources>

In the code I access the value like this:

Boolean isSplit = getResources().getBoolean(R.bool.is_split_actionbar);

To get the actionbar height in the onCreateView() method:

TypedValue typedVal = new TypedValue();
getActivity().getTheme().resolveAttribute(R.attr.actionBarSize, typedVal, true); // use android.R when not using ABS
int actionBarHeight = getResources().getDimensionPixelSize(typedVal.resourceId);

And double the height if the actionbar is split:

if(isSplit) 
    actionBarHeight = actionBarHeight * 2;

It is not an ideal solution, but for me this works.




回答3:


The bottom bar should match the height of the regular action bar. Thus, using ?android:attr/actionBarSize (or in ActionBarSherlock's case ?attr/actionBarSize) for the height in XML or getResources().getDimensionPixelSize(R.attr.actionBarSize) in code should suffice.

edit:

Er, on a second read of your question it seems more focused on also determining whether or not the split action bar exists.

You may want to read these answers and the follow-up comments by Adam Powell, action bar guru:

  • https://stackoverflow.com/a/8280776/132047
  • https://stackoverflow.com/a/8381191/132047


来源:https://stackoverflow.com/questions/10105473/determine-if-action-bar-is-split

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!