Determine if action bar is split

前端 未结 3 733
-上瘾入骨i
-上瘾入骨i 2021-01-11 23:31

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

3条回答
  •  温柔的废话
    2021-01-11 23:38

    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

    
    
    
        false
    
    
    
    
    
        true
    
    

    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.

提交回复
热议问题