【问题标题】:TabHost containing a tabwidget that does not start a activityTabHost 包含不启动活动的 tabwidget
【发布时间】:2012-06-12 09:21:16
【问题描述】:

我有 4 个选项卡小部件,当我单击其中的前三个时,它们必须启动各自的活动,当我单击第四个选项卡时,布局应该是背景上的前一个活动,并且选项卡正下方的快速操作类型对话框必须弹出窗口。这可能吗。有人请给建议。

【问题讨论】:

    标签: android android-activity tabs


    【解决方案1】:

    希望这会有所帮助! 在您的类 TabhostActivity(扩展 TabActivity)中,您必须添加:

    Resources res = getResources();
        TabHost tabHost = getTabHost();
        TabHost.TabSpec spec;
        Intent intent;
    
        // Create an Intent to launch an Activity for the tab (to be reused)
        intent = new Intent().setClass(this, your_first_tab.class);
    
        // Initialize a TabSpec for the first tab
        spec = tabHost.newTabSpec("").setIndicator("",res.getDrawable(R.drawable.ic_tab_name_of_the_first_tab)).setContent(intent);
        tabHost.addTab(spec);
    
    // Initialize a TabSpec for the second tab
        intent = new Intent().setClass(this, your_second_tab.class);
        spec = tabHost.newTabSpec("").setIndicator("",res.getDrawable(R.drawable.ic_tab_name_of_the_second_tab)).setContent(intent);
        tabHost.addTab(spec);
    

    其他人也一样。


    ic_tab_name_of_the_first_tab 是这样的 xml 文件:

    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- When selected, use grey -->
    <item android:drawable="@drawable/first_icon_grey"
          android:state_selected="true" />
    <!-- When not selected, use white-->
    <item android:drawable="@drawable/first_icon_white" />
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-01-08
      • 1970-01-01
      • 2023-04-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多