简体   繁体   English

Android:RTL ActionBar菜单项

[英]Android: RTL ActionBar Menu Items

I'm using ActionBarRTLizer for making the Home Button and the MenuItem s to be from right to left instead from left to right, and i got it working in the MainActivity and everything is good except that when i open a Fragment using the Fragment Transaction the ActionBar returns to it's default state (LTR). 我使用ActionBarRTLizer制作的Home ButtonMenuItem s到是从右到左,而不是由左到右,而我得到它的工作MainActivity ,一切都只是很好,当我打开一个FragmentFragment Transaction的ActionBar返回其默认状态(LTR)。

So i tried to @Override the onPrepareOptionsMenu() in the fragment but it didn't work. 所以我试图@OverrideonPrepareOptionsMenu()的片段,但没有奏效。 The ActionBar just got messed up.(see Below screenshots ActionBar刚刚搞砸了。

Anyone knows how to deal with that ? 有人知道如何处理吗?

Thanks in advance 提前致谢

EDITED: 编辑:

This is onCreateOptionsMenu in MainActivity: 这是MainActivity中的onCreateOptionsMenu

@Override
    public boolean onCreateOptionsMenu(Menu menu) {
        super.onCreateOptionsMenu(menu);
        getMenuInflater().inflate(R.menu.main, menu);

        ActionBarRtlizer rtlizer = new ActionBarRtlizer(this);
        ViewGroup homeView = (ViewGroup) rtlizer.getHomeView();

        RtlizeEverything.rtlize(rtlizer.getActionBarView());

        if (rtlizer.getHomeViewContainer() instanceof ViewGroup) {
            RtlizeEverything.rtlize((ViewGroup) rtlizer.getHomeViewContainer());
        }

        RtlizeEverything.rtlize(homeView);
        rtlizer.flipActionBarUpIconIfAvailable(homeView);

        return true;
    }

And this is the overridden onPrepareOptionsMenu in the fragment: 这是片段中的onPrepareOptionsMenu重写:

@Override
    public void onPrepareOptionsMenu(Menu menu) {
        getActivity().getMenuInflater().inflate(R.menu.main, menu);
        ActionBarRtlizer rtlizer = new ActionBarRtlizer(getActivity());
        ViewGroup homeView = (ViewGroup) rtlizer.getHomeView();

        RtlizeEverything.rtlize(rtlizer.getActionBarView());

        if (rtlizer.getHomeViewContainer() instanceof ViewGroup) {
            RtlizeEverything.rtlize((ViewGroup) rtlizer.getHomeViewContainer());
        }

        RtlizeEverything.rtlize(homeView);
        rtlizer.flipActionBarUpIconIfAvailable(homeView);
        if(radioPlayer.isPlaying()){
            menu.findItem(R.id.action_live_stream).setIcon(R.drawable.ic_action_stop);
        }
    }

这是主要的动作栏

And this is after i open a fragment: 这是我打开一个片段后:

在此处输入图片说明

Please try overriding onPrepareOptionsMenu and place all the lines of code after getMenuInflater().inflate(R.menu.main, menu); 请尝试覆盖onPrepareOptionsMenu并将所有代码行放在getMenuInflater()。inflate(R.menu.main,menu);之后; in it 在里面

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM