2017-10-07 81 views
-1

我试图找到一种方法来显示在我的应用程序栏中的菜单XML文件,我卡住了,所以我寻求帮助。如何显示应用程序栏(菜单)xml文件

这是我这么远:

主要活动的xml:

<android.support.v7.widget.Toolbar 
    android:id="@+id/my_toolbar" 
    android:layout_width="match_parent" 
    android:layout_height="?attr/actionBarSize" 
    android:background="?attr/colorPrimary" 
    android:elevation="4dp" 
    android:theme="@style/ThemeOverlay.AppCompat.ActionBar" 
    android:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> 

主要活动的java:

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    Toolbar myToolbar = (Toolbar) findViewById(R.id.my_toolbar); 
    setSupportActionBar(myToolbar); 

} 

,并在菜单文件夹中的XML文件。

目前正在显示在应用栏的仅仅是应用程序的名称。(有也应该是一个没有被显示的设置项)

我必须某处崇敬,其中XML文件是还是必须编辑另一个xml文件?或者我是否完全错过了某些东西?

我按照本指南中的步骤操作:https://developer.android.com/training/appbar/setting-up.html

如果你需要,我很想念请询问任何信息。感谢您的帮助。

回答

0

我忘了补充类似的东西:

@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    // Inflate the menu; this adds items to the action bar if it is present. 
    getMenuInflater().inflate(R.menu.main_activity_actions, 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_settings) { 
     return true; 
    } 

    return super.onOptionsItemSelected(item); 
} 
相关问题