how to change the position of the menu item of the action bar to left

风格不统一 提交于 2019-12-14 02:49:34

问题


i have an activity that has an action bar and i want to change the position of the menu item from right (default) to left. All the information that i have found so far, doesn't show a soluction with in the menu_main.xml , i quote code from the activity and menu_main.xml . Thank you.

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

}

code from 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"/>

I wish there was an attribute like android:layout-Gravity = "left" , something like this.

来源:https://stackoverflow.com/questions/31295114/how-to-change-the-position-of-the-menu-item-of-the-action-bar-to-left

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!