/**
* 設(shè)置選中的效果
*/
private void SetFocus(int index)
{
for(int i=0;i《title.length;i++)
{
if(i!=index)
{
title[i].setBackgroundDrawable(new ColorDrawable(unselcolor));//設(shè)置沒(méi)選中的顏色
title[i].setTextColor(fontColor);//設(shè)置沒(méi)選中項(xiàng)的字體顏色
}
}
title[index].setBackgroundColor(0x00);//設(shè)置選中項(xiàng)的顏色
title[index].setTextColor(selcolor);//設(shè)置選中項(xiàng)的字體顏色
}
public View getView(int position, View convertView, ViewGroup parent) {
View v;
if (convertView == null) {
v = title[position];
} else {
v = convertView;
}
return v;
}
}
}
testTabMenu介紹了數(shù)據(jù)的定義以及TabMenu的使用,源碼如下:
?。踛ava] view plaincopyprint?
package com.testTabMenu;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Gravity;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Toast;
public class testTabMenu extends Activity {
TabMenu.MenuBodyAdapter []bodyAdapter=new TabMenu.MenuBodyAdapter[3];
TabMenu.MenuTitleAdapter titleAdapter;
TabMenu tabMenu;
int selTitle=0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//設(shè)置分頁(yè)欄的標(biāo)題
titleAdapter = new TabMenu.MenuTitleAdapter(this, new String[] { “常用”,
“設(shè)置”, “工具” }, 16, 0xFF222222,Color.LTGRAY,Color.WHITE);
//定義每項(xiàng)分頁(yè)欄的內(nèi)容
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[] { “設(shè)置1”, “設(shè)置2”,
“設(shè)置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);//出現(xiàn)與消失的動(dòng)畫(huà)
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)+“項(xiàng)”;
Toast.makeText(testTabMenu.this, str, 500).show();
}
}
@Override
/**
* 創(chuàng)建MENU
*/
public boolean onCreateOptionsMenu(Menu menu) {
menu.add(“menu”);// 必須創(chuàng)建一項(xiàng)
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 則顯示系統(tǒng)menu
}
}
package com.testTabMenu;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Gravity;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Toast;
public class testTabMenu extends Activity {
TabMenu.MenuBodyAdapter []bodyAdapter=new TabMenu.MenuBodyAdapter[3];
TabMenu.MenuTitleAdapter titleAdapter;
TabMenu tabMenu;
int selTitle=0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//設(shè)置分頁(yè)欄的標(biāo)題
titleAdapter = new TabMenu.MenuTitleAdapter(this, new String[] { “常用”,
“設(shè)置”, “工具” }, 16, 0xFF222222,Color.LTGRAY,Color.WHITE);
評(píng)論
查看更多