简体   繁体   中英

Android Tab Layout with View Pager

i am using tab layout with view pager which contains 4 tabs and my question is,how to set onLongClickListener on the tab and then rename it? Thanks in Advance.!

for onLongClickListener

View tabView= mTabHost.getTabWidget().getChildAt(i);
// set the tag information at the view of the tab (the tag contains the position number of the tab)
tabView.setTag( Integer.valueOf(i));
tabView.setOnLongClickListener(new OnLongClickListener() {

            @Override
            public boolean onLongClick(View v) {
                // TODO Auto-generated method stub
                // I print the number position of the tab
                Log.d("tab number", ((Integer)view.getTag()).toString() );
                return false;
            }
        });

for Rename tab

((TextView)((RelativeLayout)getTabWidget().getChildAt(tabIndex)).getChildAt(textIndex)).setText("NewTabText");
try like this.

 private void changeTabsText() {

    ViewGroup vg = (ViewGroup) tabLayout.getChildAt(0);
    int tabsCount = vg.getChildCount();
    for (int j = 0; j < tabsCount; j++) {
        ViewGroup vgTab = (ViewGroup) vg.getChildAt(j);
        int tabChildsCount = vgTab.getChildCount();
        for (int i = 0; i < tabChildsCount; i++) {
            View tabViewChild = vgTab.getChildAt(i);
            if (tabViewChild instanceof TextView) {
                ((TextView) tabViewChild).setText("your Text");
            }
        }
    }
} 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM