我正在创建一个简单的应用程序,它总共有 3 个活动
- 登录 - 拥有用户名、密码字段以及登录和注册按钮
- 注册 - 具有各种表单字段和提交按钮
- 留言- 登录成功后进入本次活动
我使用 tabhost,它有 3 个选项卡,定义了上述 3 个活动。单击选项卡时,我可以在各个活动之间切换,但是当我使用表单上的按钮进行切换时,我看不到选项卡。我想在屏幕上显示标签,无论是从标签还是按钮切换。是否有任何概念,例如维护选项卡布局并且仅更改框架中的活动...我听说过 tabhost 组但无法使用它...有可能吗?保护你
我的标签主机代码是
public class TabActivity extends android.app.TabActivity
{
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.tab);
/** TabHost will have Tabs */
TabHost tabHost = (TabHost)findViewById(android.R.id.tabhost);
/** TabSpec used to create a new tab.
* By using TabSpec only we can able to setContent to the tab.
* By using TabSpec setIndicator() we can set name to tab. */
/** tid1 is firstTabSpec Id. Its used to access outside. */
TabSpec signinTab = tabHost.newTabSpec("tid1");
TabSpec signupTab = tabHost.newTabSpec("tid2");
TabSpec messageTab = tabHost.newTabSpec("tid3");
/** TabSpec setIndicator() is used to set name for the tab. */
/** TabSpec setContent() is used to set content for a particular tab. */
signinTab.setIndicator("Sign In").setContent(new Intent(getApplicationContext(),SignIn.class));
signupTab.setIndicator("Sign Up").setContent(new Intent(getApplicationContext(),MainActivity.class));
messageTab.setIndicator("Message").setContent(new Intent(getApplicationContext(),MessageDisplay.class));
/** Add tabSpec to the TabHost to display. */
tabHost.addTab(signinTab);
tabHost.addTab(signupTab);
tabHost.addTab(messageTab);//set Windows tab as default (zero based)
// tabHost.setCurrentTab(2);
}
}