Mic*_*ney 6 android menu title
我一直在摆弄android,我一直在关注菜单示例,它运行得很好,但菜单项的"标题"字段没有显示.
我认为这与这个问题有关:https: //stackoverflow.com/questions/3286093/android-menu-item-not-showing-text 但我不确定他的回答是什么意思.
无论如何,它正确地得到我有2个菜单项,它只是没有显示文本.我不太确定错误在哪里,并且认为额外的眼睛会很好.
XML:
<?xml version="1.0" encoding="UTF-8"?>
<menu xmlns:android="https://schemas.android.com/apk/res/android">
<item android:id="@+id/options"
android:title="@string/main_options" />
<item android:id="@+id/options2"
android:title="@string/main_options2" />
</menu>
Run Code Online (Sandbox Code Playgroud)
气筒:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main_menu, menu);
return true;
}
Run Code Online (Sandbox Code Playgroud)
如果需要其他任何东西,请告诉我.
编辑:字符串文件:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World!</string>
<string name="app_name">LifeInColor</string>
<string name="main_options">Options</string>
<string name="main_options2">Something goes here</string>
</resources>
Run Code Online (Sandbox Code Playgroud)
将xml更改为:
<?xml version="1.0" encoding="UTF-8"?>
<menu xmlns:android="https://schemas.android.com/apk/res/android">
<item android:id="@+id/options"
android:title="@string/main_options" />
<item android:id="@+id/options2"
android:title="Something goes here" />
</menu>
Run Code Online (Sandbox Code Playgroud)
获得相同的结果.我有一张照片,但它不会让我发布它,因为我是新的.
在您的菜单文件中替换https://schemas.android.com/apk/res/android为http://schemas.android.com/apk/res/android( https -> http )。所以看来错误是由于架构地址不正确造成的。