如何更改操作栏的菜单项的位置向左(how to change the position of the

2019-10-23 17:19发布

我有一个具有操作栏中选择一个活动,我想改变菜单项的位置从右(默认值)到左。 所有我发现,到目前为止,并没有显示出与在menu_main.xml一个soluction的信息,我引用从活动和menu_main.xml代码。 谢谢。

public class GadgetFlowWeb extends AppCompatActivity {

View mView;
GadgetItem mData;
Context ctx;
private ImageButton mBtnReload;
private ImageButton mBtnNext;
private ImageButton mBtnPrev;
private ImageButton mBtnOpenIn;
private WebView mWebview;
private boolean mIsLoadFinish = false;
private ActionBar mActionBar;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //Log.d("billy","inside GadgetFlowWeb");
    savedInstanceState = getIntent().getExtras().getBundle("data");
    //Getting the actionBar
    mActionBar = getSupportActionBar();
    mActionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#f26253"))); //changing color of the action bar 

    if (savedInstanceState != null)
        mData = (GadgetItem) savedInstanceState.getSerializable("data");

    setContentView(R.layout.activity_gadget_flow_web);
    /*
     * vf: initialize the widgets
     */
    if (mData != null) {
        //Log.e("nhatdo", "data webview " + mData.gadget_buyLink);
        ((WebView) findViewById(R.id.wvBuyItem)).loadUrl(mData.gadget_buyLink);
        mActionBar.setTitle(mData.gadget_title);

    }
    ...

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_main, menu);
    menu.findItem(R.id.action_search).setVisible(false);
    menu.findItem(R.id.action_share).setVisible(false);
    menu.findItem(R.id.action_back).setVisible(true);

    return true;
}

}

从menu_main.xml代码:

<menu xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  xmlns:tools="http://schemas.android.com/tools"
  tools:context=".MainActivity">
  <!-- search -->
  <item android:id="@+id/action_search"
        android:icon="@drawable/ic_search"
        android:title="search"
        app:showAsAction="always"
        android:visible="false"/>
  <item android:id="@+id/action_share"
      android:icon="@drawable/ic_share"
      android:title="share"
      app:showAsAction="ifRoom"
      android:visible="false"/>
  <item android:id="@+id/action_back"
      android:icon="@drawable/ic_back"
      android:title = "back"
      app:showAsAction="always"
      android:visible="false"/>

我希望能有像Android这样一个属性:布局重力=“左”,这样的事情。

文章来源: how to change the position of the menu item of the action bar to left