如何将操作栏菜单项的位置更改为左侧

时间:2015-07-08 14:05:17

标签: android android-actionbar

我的活动有一个操作栏,我想将菜单项的位置从右(默认)更改为左。到目前为止我找到的所有信息都没有在menu_main.xml中显示解决方案,我引用了活动和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这样的属性:layout-Gravity =&#34; left&#34; ,像这样的东西。

0 个答案:

没有答案