我在menu.xml中有这段代码,它位于导航视图中:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group>
<item
android:title="Blue"
android:id="@+id/blue">
<menu>
<item
android:id="@+id/red"
android:title="Red"
/>
</menu>
</item>
</group>
<group>
<item
android:id="@+id/green"
android:title="Green" />
<item
android:id="@+id/yellow"
android:title="Yellow"/>
</group>
</menu>
我想只更改蓝色项目文字大小。我怎么能这样做?
答案 0 :(得分:7)
创建菜单时,您可以更改文字大小:
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
MenuInflater awesome = getMenuInflater();
awesome.inflate(R.menu.menu_main, menu);
for(int i = 0; i < menu.size(); i++) {
MenuItem item = menu.getItem(i);
if (item.getItemId() == R.id.blue)
{
SpannableString spanString = new SpannableString(menu.getItem(i).getTitle().toString());
int end = spanString.length();
spanString.setSpan(new RelativeSizeSpan(1.5f), 0, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
item.setTitle(spanString);
}
}
return true;
}