2015-04-03 104 views
1

我使用ActionBarRTLizer使Home ButtonMenuItem是從右到左,而不是從左到右,我得到它在MainActivity工作,一切都很好,除了當我使用Fragment Transaction打開Fragment,ActionBar返回它的默認狀態(LTR)。Android:RTL ActionBar菜單項

所以我試圖@OverrideonPrepareOptionsMenu()在片段,但它沒有奏效。該ActionBar剛剛搞砸了(見下面的截圖

任何人都知道如何處理與

在此先感謝

編輯:?

這是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; 
    } 

這是覆蓋在PrepareOptionsMen ü在片段:

@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); 
     } 
    } 

This is the main action bar

這是後我打開一個片段:

enter image description here

回答

1

請嘗試重寫onPrepareOptionsMenu並將所有getMenuInflater後的代碼行() .inflate(R.menu.main,菜單);在它

+0

我試過了,但'actionbar'搞砸了,看到我編輯的問題請 – 2015-04-03 17:48:24

+0

你可以只在onCreateOptionsMenu有inflater代碼,其餘的在onPrepareOptionsMenu – 2015-04-03 18:06:41

+0

並且在活動中有onPrepare而不在片段中 – 2015-04-03 18:07:31