我一直在尝试将动态创建的菜单转换为xml菜单并获取ActionBarSherlock以正确地对其进行充气。我确实在动作栏上放了一些东西,所以我做的正确。然而,结果并不奇怪。
我做错了什么还是这个错误?
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="@+id/menu_save" android:showAsAction="always|withText" android:title="Save" android:visible="true"/>
<menu android:id="@+id/menu_para" android:showAsAction="always|withText" android:title="H" android:visible="true">
<item android:id="@+id/para_h1" android:showAsAction="always|withText" android:title="H1" android:visible="true"/>
<item android:id="@+id/para_h2" android:showAsAction="always|withText" android:title="H2" android:visible="true"/>
<item android:id="@+id/para_h3" android:showAsAction="always|withText" android:title="H3" android:visible="true"/>
<item android:id="@+id/para_h4" android:showAsAction="always|withText" android:title="H4" android:visible="true"/>
<item android:id="@+id/para_h5" android:showAsAction="always|withText" android:title="H5" android:visible="true"/>
<item android:id="@+id/para_text" android:showAsAction="always|withText" android:title="T" android:visible="true"/>
</menu>
<menu android:id="@+id/menu_bullets" android:showAsAction="always|withText" android:title="*1" android:visible="true">
<item android:id="@+id/bullets_dots" android:showAsAction="always|withText" android:title="*" android:visible="true"/>
<item android:id="@+id/bullets_numbers" android:showAsAction="always|withText" android:title="1" android:visible="true"/>
</menu>
<menu android:id="@+id/menu_em" android:showAsAction="always|withText" android:title="i-B" android:visible="true">
<item android:id="@+id/em_italic" android:showAsAction="always|withText" android:title="i" android:visible="true"/>
<item android:id="@+id/em_bold" android:showAsAction="always|withText" android:title="B" android:visible="true"/>
<item android:id="@+id/em_both" android:showAsAction="always|withText" android:title="iB" android:visible="true"/>
</menu>
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:showAsAction="never"
android:title="@string/action_settings">
</item>
</menu>
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getSupportActionBar().setDisplayShowTitleEnabled(false);
getSupportActionBar().setDisplayShowHomeEnabled(false);
Log.i("MyApp", "About to run inflater");
MenuInflater menuInflater = getSupportMenuInflater();
menuInflater.inflate(R.menu.editor, menu);
Log.i("MyApp", "Inflate done");
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getSupportActionBar().setDisplayShowTitleEnabled(false);
getSupportActionBar().setDisplayShowHomeEnabled(false);
Log.i("MyApp", "About to run inflater");
MenuInflater menuInflater = getSupportMenuInflater();
menuInflater.inflate(R.menu.editor, menu);
Log.i("MyApp", "Inflate done");
return super.onCreateOptionsMenu(menu);
}
import com.actionbarsherlock.app.SherlockActivity;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;
import com.actionbarsherlock.view.MenuInflater;
import android.os.Bundle;
import android.util.Log;
操作栏上显示四个按钮
SAVE
- 目前无效SAVE
- 打开一个包含H1,H2,H3,...,H6,T的菜单*
- 什么都不做1
- 什么都不做两个按钮
*
- 什么都不做1
- 什么都不做SAVE
项,则标题子菜单会完全消失,并且标题错误。*
和1
应位于子菜单中。