相关疑难解决方法(0)

Android标签帮助.应用程序打开时如何将第二个选项卡设置为默认值

我创建了一个包含3个标签的应用.该应用程序工作正常但我希望在应用程序打开时选择并加载第二个选项卡.我怎么设置?

这是我的代码:

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        TabHost tabHost = getTabHost();



        // Tab for Home
        TabSpec homespec = tabHost.newTabSpec("Home");
        // setting Title and Icon for the Tab
        homespec.setIndicator("Home",getResources().getDrawable(R.drawable.icons_home_tab));
        Intent photosIntent = new Intent(this, HomeActivity.class);
        homespec.setContent(photosIntent);

        // Tab for Child
        TabSpec childspec = tabHost.newTabSpec("Child");
        childspec.setIndicator("Child",getResources().getDrawable(R.drawable.icons_child_tab));
        Intent homeIntent = new Intent(this, ChildActivity.class);
        childspec.setContent(homeIntent);

        // Tab for Account
        TabSpec accspec = tabHost.newTabSpec("Account");
        accspec.setIndicator("Account",getResources().getDrawable(R.drawable.icons_account_tab));
        Intent accIntent = new Intent(this, AccountActivity.class);
        accspec.setContent(accIntent);

        // Adding all TabSpec to TabHost
        tabHost.addTab(homespec); // Adding home tab …
Run Code Online (Sandbox Code Playgroud)

tabs android android-tabhost

6
推荐指数
1
解决办法
1万
查看次数

标签 统计

android ×1

android-tabhost ×1

tabs ×1