[Java]
Package com. anyjoys. view. component;
Import android. app. TabActivity;
Import android. content. Intent;
Import android. graphics. drawable. Drawable;
Import android. OS. Bundle;
Import android. view. View;
Import android. widget. FrameLayout;
Import android. widget. ImageView;
Import android. widget. TabHost;
Import android. widget. TabHost. OnTabChangeListener;
Import android. widget. TabWidget;
Import android. widget. TextView;
Import com. anyjoys. R;
/**
* The basic Tab layout class includes (bottom menu and top menu management)
*
* @ Author summer
*
*/
Public class TabLayoutActivity extends TabActivity {
Private TabHost mTabHost;
Private TextView textview_unread;
Private View lastView; // record the last display View
Public TabHost getmTabHost (){
Return mTabHost;
}
Private View view1;
Public View getView1 (){
Return view1;
}
@ Override
Public void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
SetContentView (R. layout. tabhost );
This. mTabHost = (TabHost) findViewById (android. R. id. tabhost );
This. mTabHost. setOnTabChangedListener (new OnTabChangeListener (){
@ Override
Public void onTabChanged (String tabId ){
If (lastView! = Null)
LastView. setVisibility (View. GONE );
FrameLayout frameLayout = mTabHost. getTabContentView ();
FrameLayout. setVisibility (View. VISIBLE );
LastView = frameLayout;
}
});
}
/**
* Fill in the bottom menu and note that all parameters correspond one to one.
*
* @ Param menu_id
* Preset menu ID
* @ Param top_icon_resid
* Menu icon resource file Array
* @ Param str_resid
* Menu text resource file Array
* @ Param intent
* Define intent
*/
Public void setBottomMenuAndIntent (int [] menu_id, int [] top_icon_resid,
Int [] str_resid, Intent [] intent ){
If (null! = MTabHost ){
For (int j = 0; j <menu_id.length; j ++ ){
View1 = View. inflate (TabLayoutActivity. this, R. layout. tab,
Null); // menu button layout File
(ImageView) view1.findViewById (R. id. tab_imageview_icon ))
. SetImageResource (top_icon_resid [j]);
(TextView) view1.findViewById (R. id. tab_textview_title ))
. SetText (str_resid [j]);
View1.setBackgroundResource (R. drawable. bottom_btn_bg );
/* Initialization intent */
MTabHost. addTab (buildTabSpec (menu_id [j] + "", view1,
Intent [j]);
}
}
}
/**
* Hide the bottom?
*
* @ Param isvisibility
*/
Public void hideBottomMenu (boolean isvisibility ){
If (isvisibility ){
This. mTabHost. getTabWidget (). setVisibility (View. GONE );
} Else {
This. mTabHost. getTabWidget (). setVisibility (View. VISIBLE );
}
}
/**
* Set the background image at the bottom.
*/
Public void setTabBackground (int bg_resid ){
This. mTabHost. getTabWidget (). setBackgroundResource (bg_resid );
}
/**
* Initialize the tab
*
* @ Param tag
* @ Param view
* @ Param content
* @ Return
*/
Private TabHost. TabSpec buildTabSpec (String tag, View view,
Final Intent content ){
Return mTabHost. newTabSpec (tag). setIndicator (view)
. SetContent (content );
}
/**
* Start intent
*
* @ Param menu_id
*/
Public void startIabIntent (int menu_id ){
This. mTabHost. setCurrentTabByTag (menu_id + "");
}
/**
* You must construct a menu before calling this method. Otherwise, it will not be displayed.
* Message display in menu options
* @ Param postion: select the display menu position. If it is greater than the menu item, the default value is 0.
* @ Param bgimgres: the background icon of the message. Optional values: 0.
* @ Param num: Display quantity
*/
Public void setTipStr (int postion, int bgimgres, int num ){
TabWidget tab = getmTabHost (). getTabWidget ();
Int count = tab. getChildCount ();
If (count> 0 ){
Postion = postion> count? 0: postion-1;
View menuview = tab. getChildAt (postion );
Textview_unread = (TextView) menuview. findViewById (R. id. tab_textview_unread );
Textview_unread.setVisibility (View. VISIBLE );
If (bgimgres! = 0 ){
If (getResources (). getDrawable (bgimgres) instanceof Drawable ){
Textview_unread.setBackgroundResource (bgimgres );
}
}
Textview_unread.setText (num + "");
}
}
/**
* Hide menu messages
* @ Param postion if it is greater than the menu item, the default value is 0.
*/
Public void hideTipStr (int postion ){
TabWidget tab = getmTabHost (). getTabWidget ();
Int count = tab. getChildCount ();
If (count> 0 ){
Postion = postion> count? 0: postion-1;
View menuview = tab. getChildAt (postion );
Textview_unread = (TextView) menuview. findViewById (R. id. tab_textview_unread );
Textview_unread.setVisibility (View. GONE );
}
}
}
Package com. anyjoys. view. component;
Import android. app. TabActivity;
Import android. content. Intent;
Import android. graphics. drawable. Drawable;
Import android. OS. Bundle;
Import android. view. View;
Import android. widget. FrameLayout;
Import android. widget. ImageView;
Import android. widget. TabHost;
Import android. widget. TabHost. OnTabChangeListener;
Import android. widget. TabWidget;
Import android. widget. TextView;
Import com. anyjoys. R;
/**
* The basic Tab layout class includes (bottom menu and top menu management)
*
* @ Author summer
*
*/
Public class TabLayoutActivity extends TabActivity {
Private TabHost mTabHost;
Private TextView textview_unread;
Private View lastView; // record the last display View
Public TabHost getmTabHost (){
Return mTabHost;
}
Private View view1;
Public View getView1 (){
Return view1;
}
@ Override
Public void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
SetContentView (R. layout. tabhost );
This. mTabHost = (TabHost) findViewById (android. R. id. tabhost );
This. mTabHost. setOnTabChangedListener (new OnTabChangeListener (){
@ Override
Public void onTabChanged (String tabId ){
If (lastView! = Null)
LastView. setVisibility (View. GONE );
FrameLayout frameLayout = mTabHost. getTabContentView ();
FrameLayout. setVisibility (View. VISIBLE );
LastView = frameLayout;
}
});
}
/**
* Fill in the bottom menu and note that all parameters correspond one to one.
*
* @ Param menu_id
* Preset menu ID
* @ Param top_icon_resid
* Menu icon resource file Array
* @ Param str_resid
* Menu text resource file Array
* @ Param intent
* Define intent
*/
Public void setBottomMenuAndIntent (int [] menu_id, int [] top_icon_resid,
Int [] str_resid, Intent [] intent ){
If (null! = MTabHost ){
For (int j = 0; j <menu_id.length; j ++ ){
View1 = View. inflate (TabLayoutActivity. this, R. layout. tab,
Null); // menu button layout File
(ImageView) view1.findViewById (R. id. tab_imageview_icon ))
. SetImageResource (top_icon_resid [j]);
(TextView) view1.findViewById (R. id. tab_textview_title ))
. SetText (str_resid [j]);
View1.setBackgroundResource (R. drawable. bottom_btn_bg );
/* Initialization intent */
MTabHost. addTab (buildTabSpec (menu_id [j] + "", view1,
Intent [j]);
}
}
}
/**
* Hide the bottom?
*
* @ Param isvisibility
*/
Public void hideBottomMenu (boolean isvisibility ){
If (isvisibility ){
This. mTabHost. getTabWidget (). setVisibility (View. GONE );
} Else {
This. mTabHost. getTabWidget (). setVisibility (View. VISIBLE );
}
}
/**
* Set the background image at the bottom.
*/
Public void setTabBackground (int bg_resid ){
This. mTabHost. getTabWidget (). setBackgroundResource (bg_resid );
}
/**
* Initialize the tab
*
* @ Param tag
* @ Param view
* @ Param content
* @ Return
*/
Private TabHost. TabSpec buildTabSpec (String tag, View view,
Final Intent content ){
Return mTabHost. newTabSpec (tag). setIndicator (view)
. SetContent (content );
}
/**
* Start intent
*
* @ Param menu_id
*/
Public void startIabIntent (int menu_id ){
This. mTabHost. setCurrentTabByTag (menu_id + "");
}
/**
* You must construct a menu before calling this method. Otherwise, it will not be displayed.
* Message display in menu options
* @ Param postion: select the display menu position. If it is greater than the menu item, the default value is 0.
* @ Param bgimgres: the background icon of the message. Optional values: 0.
* @ Param num: Display quantity
*/
Public void setTipStr (int postion, int bgimgres, int num ){
TabWidget tab = getmTabHost (). getTabWidget ();
Int count = tab. getChildCount ();
If (count> 0 ){
Postion = postion> count? 0: postion-1;
View menuview = tab. getChildAt (postion );
Textview_unread = (TextView) menuview. findViewById (R. id. tab_textview_unread );
Textview_unread.setVisibility (View. VISIBLE );
If (bgimgres! = 0 ){
If (getResources (). getDrawable (bgimgres) instanceof Drawable ){
Textview_unread.setBackgroundResource (bgimgres );
}
}
Textview_unread.setText (num + "");
}
}
/**
* Hide menu messages
* @ Param postion if it is greater than the menu item, the default value is 0.
*/
Public void hideTipStr (int postion ){
TabWidget tab = getmTabHost (). getTabWidget ();
Int count = tab. getChildCount ();
If (count> 0 ){
Postion = postion> count? 0: postion-1;
View menuview = tab. getChildAt (postion );
Textview_unread = (TextView) menuview. findViewById (R. id. tab_textview_unread );
Textview_unread.setVisibility (View. GONE );
}
}
}