[英]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 Button
和MenuItem
s到是从右到左,而不是由左到右,而我得到它的工作MainActivity
,一切都只是很好,当我打开一个Fragment
用Fragment Transaction
的ActionBar返回其默认状态(LTR)。
So i tried to @Override
the onPrepareOptionsMenu()
in the fragment but it didn't work. 所以我试图
@Override
的onPrepareOptionsMenu()
的片段,但没有奏效。 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.