//定義每項分頁欄的內容
bodyAdapter[0]=new TabMenu.MenuBodyAdapter(this,new String[] { “常用1”, “常用2”, },
new int[] { R.drawable.menu_test,
R.drawable.menu_bookmark},13, 0xFFFFFFFF);
bodyAdapter[1]=new TabMenu.MenuBodyAdapter(this,new String[] { “設置1”, “設置2”,
“設置3”}, new int[] { R.drawable.menu_edit,
R.drawable.menu_delete, R.drawable.menu_fullscreen},13, 0xFFFFFFFF);
bodyAdapter[2]=new TabMenu.MenuBodyAdapter(this,new String[] { “工具1”, “工具2”,
“工具3”, “工具4” }, new int[] { R.drawable.menu_copy,
R.drawable.menu_cut, R.drawable.menu_normalmode,
R.drawable.menu_quit },13, 0xFFFFFFFF);
tabMenu=new TabMenu(this,
new TitleClickEvent(),
new BodyClickEvent(),
titleAdapter,
0x55123456,//TabMenu的背景顏色
R.style.PopupAnimation);//出現與消失的動畫
tabMenu.update();
tabMenu.SetTitleSelect(0);
tabMenu.SetBodyAdapter(bodyAdapter[0]);
}
class TitleClickEvent implements OnItemClickListener{
@Override
public void onItemClick(AdapterView《?》 arg0, View arg1, int arg2,
long arg3) {
selTitle=arg2;
tabMenu.SetTitleSelect(arg2);
tabMenu.SetBodyAdapter(bodyAdapter[arg2]);
}
}
class BodyClickEvent implements OnItemClickListener{
@Override
public void onItemClick(AdapterView《?》 arg0, View arg1, int arg2,
long arg3) {
tabMenu.SetBodySelect(arg2,Color.GRAY);
String str=“第”+String.valueOf(selTitle)+“欄/n/r”
+“第”+String.valueOf(arg2)+“項”;
Toast.makeText(testTabMenu.this, str, 500).show();
}
}
@Override
/**
* 創建MENU
*/
public boolean onCreateOptionsMenu(Menu menu) {
menu.add(“menu”);// 必須創建一項
return super.onCreateOptionsMenu(menu);
}
@Override
/**
* 攔截MENU
*/
public boolean onMenuOpened(int featureId, Menu menu) {
if (tabMenu != null) {
if (tabMenu.isShowing())
tabMenu.dismiss();
else {
tabMenu.showAtLocation(findViewById(R.id.LinearLayout01),
Gravity.BOTTOM, 0, 0);
}
}
return false;// 返回為true 則顯示系統menu
}
}
評論
查看更多