简体   繁体   中英

How do I change the android actionbar title with tab menu?

选择标签菜单时如何更改android操作栏标题?

In your onPageSelected() , try following code,

 getSupportActionBar().setTitle("My Title");;

This may helps you.

public class TabAdapter extends FragmentPagerAdapter implements ActionBar.TabListener , ViewPager.OnPageChangeListener{
   int resId = {R.drawable.position0, R.drawable.position1, R.drawable.position2, R.drawable.position3, R.drawable.position4};

 @Override
public void onPageSelected(int position) {
    mActionBar.setSelectedNavigationItem(position);
    int resIdLenght = resId.length;
    if (position < 0 || position >= resIdLenght)
            return;
    int drawableId = resId[position];
    mActionBar.setIcon(drawableId);  
}


}

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