【发布时间】:2014-03-23 10:42:06
【问题描述】:
我有以下 Android Java 和 XML 代码。我想更改我的应用程序菜单项的字体。我只知道我们可以使用 setTypeface 更改 TextView 的字体,但无论如何都找不到菜单项。
JAVA代码-:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_refresh1:
Toast.makeText(this, "Item1 Selected", Toast.LENGTH_SHORT)
.show();
break;
case R.id.action_refresh2:
Toast.makeText(this, "Item2 Selected", Toast.LENGTH_SHORT)
.show();
break;
default:
break;
}
}
XML 代码-:
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/action_refresh1"
android:orderInCategory="100"
android:showAsAction="always"
android:title="Item1"/>
<item
android:id="@+id/action_refresh2"
android:orderInCategory="100"
android:showAsAction="always"
android:title="Item2"/>
</menu>
我想改变两个菜单项的字体,但不知道如何为菜单项集成settypface。
【问题讨论】:
-
也许这会给你一个提示 :) 请看下面的答案 :) stackoverflow.com/questions/4135699/…