我在侧面菜单中的应用程序菜单上有这样的代码:
主要的.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/menu"
android:showAsAction="always"
android:title="@string/menu">
<menu>
<item android:id="@+id/edit"
android:title="@string/edit"
android:icon="@android:drawable/ic_menu_edit"/>
</menu>
</item>
</menu>
MainActive.java
boolean isEdit=false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.history);
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
isEdit=sp.getBoolean("isEdit", false);
}
public boolean onCreateOptionsMenu(android.view.Menu menu) {
android.view.MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main, menu);
if(isEdit)
// change R.id.edit title to "test1"
return true;
}
如何从 if(isEdit) 条件更改 R.id.edit 标题?!