[英]android - Action bar sherlock add unnecessary button
我使用動作欄夏洛克,並在菜單中設置自定義布局:
<item
android:id="@+id/action_menu"
android:actionLayout="@layout/menu_item"
android:icon="@drawable/b_menu"
android:orderInCategory="1"
android:showAsAction="always"/>
<item
android:id="@+id/action_audio"
android:actionLayout="@layout/audio_item"
android:icon="@drawable/b_audio"
android:orderInCategory="2"
android:showAsAction="always"/>
<item
android:id="@+id/action_mySong_details"
android:actionLayout="@layout/my_song_properties"
android:icon="@drawable/b_mysong"
android:orderInCategory="2"
android:showAsAction="always"/>
控制我使用的那些項目:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
/** Create an option menu from res/menu/items.xml */
getSherlock().getMenuInflater().inflate(R.menu.main_tab, menu);
/** Get the action view of the menu item whose id is search */
View v = (View) menu.findItem(R.id.action_menu).getActionView();
Button b = (Button) v.findViewById(R.id.btnMenu);
return super.onCreateOptionsMenu(menu);
}
由於某種原因,操作欄會添加不必要的項目,有人知道這種情況如何發生嗎?
您正在使用操作欄夏洛克。 因此,請使用SupportMenuInflater。
public boolean onCreateOptionsMenu(com.actionbarsherlock.view.Menu menu) {
com.actionbarsherlock.view.MenuInflater inflater = getSupportMenuInflater();
inflater.inflate(R.layout.menu, menu);
}
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.action_menu:
// Intent i=new Intent(A.this,B.class);
//startActivity(i);
return true;
}
return false;
}
我發現了錯誤:我從所有項目中刪除了android:orderInCategory,現在可以了,在這種情況下,我不需要此選項。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.