Troubleshoot the Android tabhost individual version view overlap problem

Source: Internet
Author: User

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;

/**

* Tab Layout base 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 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 the bottom menu note that all parameters one by one correspond

*

* @param menu_id

* Pre-set Menu ID

* @param top_icon_resid

* Menu icon resource file array

* @param str_resid

* Menu type 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]));

}

}

}

/**

* Whether to 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 bottom background picture

*/

public void Settabbackground (int bg_resid) {

This.mTabHost.getTabWidget (). Setbackgroundresource (BG_RESID);

}

/**

* Initialize 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 to start intent intent

*

* @param menu_id

*/

public void startiabintent (int menu_id) {

This.mTabHost.setCurrentTabByTag (menu_id + "");

}

/**

* The menu must be constructed before the method is called, or it is not displayed

* Message Display in menu options

* @param postion Select Show menu Location if greater than menu item defaults to 0

* @param the background icon of the bgimgres message is optional 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 Message

* @param postion if greater than the menu item defaults to 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);

}

}

}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.