Actionbar scherlock is not refreshed when the orientation is changed

限于喜欢 提交于 2019-12-19 03:24:26

问题


I use Sherlock action bar in my application. I used "ifRoom|withText" feature in my menu. If I test my code in portrait mode, I can see only icon and if I rotate orientation to landscape, still I see only icon. On the other hand, if I run with landscape, I can see text and icon on portrait and landscape. This means that When the screen is rotated, action bar is not refreshed. How can I fix?

In menu, I have

    android:showAsAction="ifRoom|withText"

Also I used this line in my manifest file to fixed

    android:configChanges="keyboardHidden|orientation|screenSize"

but it didn't work. And I run my code android 2.3

Also I used fragment in my activity,

        FragmentManager fm = getSupportFragmentManager();
    ft = fm.beginTransaction();

    mFragment1 = fm.findFragmentByTag("f1");

    if (mFragment1 == null) {

        mFragment1 = new MenuFragment();
        ft.add(mFragment1, "f1");

    }

    ft.commit();

回答1:


Handling configuration changes is not supported with ActionBarSherlock.

On pre-ICS, ActionBarSherlock is NOT part of the decor view like the native action bar and is therefore subject to the same restrictions as your content view. By handling configuration changes you are not allowing the library to adapt to the change and therefore will see incorrect display or certain parts.

The Android documentation discourages handling config changes as well. Avoid them at all costs, especially when using ActionBarSherlock.

On a related note, I'm still trying to work around this for future versions of the library but for now avoiding is recommended.




回答2:


I think you will have to re-create the ActionBar menu on config change

invalidateOptionsMenu();


来源:https://stackoverflow.com/questions/10589676/actionbar-scherlock-is-not-refreshed-when-the-orientation-is-changed

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