There is no problem with the programmatic change of the application header (I will do this via getActionBar().setTitle() ); What is the shortest way to implement getting the current tab? I know there is an onTabSelected method, but I did not find normal (= concise) examples. Ideally, I see a switch-case block surrounded by a similar onTabSelected method:

 ... tabSpec = tabHost.newTabSpec("tab1"); ... switch (tag) { case "tab1": getActionBar().setTitle("Π’ΠΊΠ»Π°Π΄ΠΊΠ°1"); case "tab2": getActionBar().setTitle("Π’ΠΊΠ»Π°Π΄ΠΊΠ°2"); case "tab3": getActionBar().setTitle("Π’ΠΊΠ»Π°Π΄ΠΊΠ°3"); case "tab4": getActionBar().setTitle("Π’ΠΊΠ»Π°Π΄ΠΊΠ°4"); default: break; } 

I created tabs via TabHost (there are other ways, as it turned out).

    1 answer 1

    Look toward TabLayout. TabHost is an ancient version. tabLayout works with the viewpager. TabLayout has addOnTabSelectedListener. There put TabLayout. OnTabSelectedListener and redefine ontabSelected

     tabs.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { @Override public void onTabSelected(TabLayout.Tab tab) { switch (tab.getPosition()) { case 0: getActionBar().setTitle("Π’ΠΊΠ»Π°Π΄ΠΊΠ°1"); break; case 1: getActionBar().setTitle("Π’ΠΊΠ»Π°Π΄ΠΊΠ°2"); break; default: break; } } @Override public void onTabUnselected(TabLayout.Tab tab) { } @Override public void onTabReselected(TabLayout.Tab tab) { } }); 
    • Thank you for your reply! Be sure to try. I have been looking for a solution for a very long time how to make an icon in the tab without a title; in TabLayout it possible to easily remove the title and leave only the icon? - Bokov Gleb
    • This is how you can set the icon - pavel163
    • tabs.addTab (tabs.newTab (). setIcon (R.drawable.walk), 1); I set this icon for the second tab. There is no default text - pavel163