2016-06-21 13 views
-1

私はアンドロイドで新しく、カスタマイズされたツールバーを作成しようとしています。クリックしたときに設定メニュー(3ドット)にオプションを追加する方法があるかどうか疑問に思っていました。Androidスタジオのメインツールバーのオプションメニューにオプションを追加する

enter image description here

enter image description here

+3

が重複する可能性のようなものを作成します36442116/custom-the-option-menu-of-main-toolbar-in-android-studio) – Ironman

+0

こんにちは。私はそのリンクをチェックした。それは私がやろうとしたものとは少し違っていました。私は解決策を見つけた。とにかくおかげで.. :) – Mehul

答えて

-1

まずようなファイル。

<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="in.amzbizsol.vts.MainActivity"> 
<item 
    android:id="@+id/action_changepassword" 
    android:orderInCategory="1" 
    android:title="Change Password" 
    app:showAsAction="never" /> 
<item 
    android:id="@+id/action_logout" 
    android:orderInCategory="2" 
    android:title="Logout" 
    app:showAsAction="never" /> 

、あなたのMainActivityで[Androidのスタジオでメインツールバーのオプションメニューをカスタマイズ](http://stackoverflow.com/questions/の

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

@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    // Handle action bar item clicks here. The action bar will 
    // automatically handle clicks on the Home/Up button, so long 
    // as you specify a parent activity in AndroidManifest.xml. 
    int id = item.getItemId(); 

    //noinspection SimplifiableIfStatement 
    if (id == R.id.action_changepassword) { 
     Intent intent=new Intent(getApplicationContext(),ChangePassword.class); 
     startActivity(intent); 
     return true; 
    }else if(id==R.id.action_logout){ 
       finish(); 
      } 
     return true; 
    } 

    return super.onOptionsItemSelected(item); 
} 
+0

ソリューションはまた質問の重複していますhttp://stackoverflow.com/questions/36442116/customize-the-option-menu-of-main-toolbar-in-android-studio –

+0

真剣に?? @ KapilRajput私はこのコードを書くのに自分の時間を費やしました。私はあなたが感謝することはできませんが、指摘する前に答えを少なくともatleast読むことを知っています。 – Akash

関連する問題