1
I have the following code.
private void TabsCadastro(int visualizar,int origem)
{
TabSpec abaCLiente,abaEndereco,abaContrato;
TabHost tabHost = getTabHost();
abaCLiente = tabHost.newTabSpec("tag1");
abaCLiente.setContent(R.id.clientes);
abaCLiente.setIndicator("Cliente");
abaEndereco = tabHost.newTabSpec("tag2");
abaEndereco.setContent(R.id.endereco);
abaEndereco.setIndicator("Endereço");
abaContrato = tabHost.newTabSpec("tag3");
abaContrato.setContent(R.id.contrato);
abaContrato.setIndicator("Contrato");
tabHost.setFocusableInTouchMode(true);
if(origem == 0)
{
tabHost.addTab(abaCLiente);
tabHost.addTab(abaEndereco);
tabHost.addTab(abaContrato);
}
tabHost.getTabWidget().setEnabled(false);
tabHost.setCurrentTab(0);
}
Would you like to know how to change the focus of tabs? I would like to create a button to change the focus instead of clicking tabs for this. I will put a button in each tab to navigate between them I tried to use
setFocused(boolean),
setFocusable(boolean),
but I couldn’t change the focus.
You have to use the
setCurrentTab()
to change tab, something like:MainActivity.TabHost.setCurrentTab(1);
.– Zuul
I don’t think you should use Tabhost anymore, because it’s too old-fashioned. Use Viewpager with that library here: https://github.com/bitjjj/PagerSlidingTitleIconTabStrip
– Cícero Moura