如何显示应用栏(菜单)xml 文件
How to display app bar (menu) xml file
我正在尝试找到一种在我的应用程序栏中显示菜单 xml 文件的方法,但我卡住了,所以我正在寻求帮助。
这是我目前得到的:
主要activityxml:
<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" />
主要activityjava:
@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
如果您需要我遗漏的任何信息,请询问。谢谢你的帮助。
我忘了添加类似的内容:
@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);
}
我正在尝试找到一种在我的应用程序栏中显示菜单 xml 文件的方法,但我卡住了,所以我正在寻求帮助。
这是我目前得到的:
主要activityxml:
<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" />
主要activityjava:
@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
如果您需要我遗漏的任何信息,请询问。谢谢你的帮助。
我忘了添加类似的内容:
@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);
}