Search in sources :

Example 26 with TabHost

use of android.widget.TabHost in project android_frameworks_base by DirtyUnicorns.

the class LaunchpadTabActivity method onCreate.

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    Intent tabIntent = new Intent(getIntent());
    tabIntent.setComponent((ComponentName) tabIntent.getParcelableExtra("tab"));
    TabHost th = getTabHost();
    TabHost.TabSpec ts = th.newTabSpec("1");
    ts.setIndicator("One");
    ts.setContent(tabIntent);
    th.addTab(ts);
}
Also used : TabHost(android.widget.TabHost) Intent(android.content.Intent)

Example 27 with TabHost

use of android.widget.TabHost in project android_frameworks_base by DirtyUnicorns.

the class RenderSessionImpl method setupTabHost.

/**
     * Sets up a {@link TabHost} object.
     * @param tabHost the TabHost to setup.
     * @param layoutlibCallback The project callback object to access the project R class.
     * @throws PostInflateException
     */
private void setupTabHost(TabHost tabHost, LayoutlibCallback layoutlibCallback) throws PostInflateException {
    // look for the TabWidget, and the FrameLayout. They have their own specific names
    View v = tabHost.findViewById(android.R.id.tabs);
    if (v == null) {
        throw new PostInflateException("TabHost requires a TabWidget with id \"android:id/tabs\".\n");
    }
    if (!(v instanceof TabWidget)) {
        throw new PostInflateException(String.format("TabHost requires a TabWidget with id \"android:id/tabs\".\n" + "View found with id 'tabs' is '%s'", v.getClass().getCanonicalName()));
    }
    v = tabHost.findViewById(android.R.id.tabcontent);
    if (v == null) {
        //noinspection SpellCheckingInspection
        throw new PostInflateException("TabHost requires a FrameLayout with id \"android:id/tabcontent\".");
    }
    if (!(v instanceof FrameLayout)) {
        //noinspection SpellCheckingInspection
        throw new PostInflateException(String.format("TabHost requires a FrameLayout with id \"android:id/tabcontent\".\n" + "View found with id 'tabcontent' is '%s'", v.getClass().getCanonicalName()));
    }
    FrameLayout content = (FrameLayout) v;
    // now process the content of the frameLayout and dynamically create tabs for it.
    final int count = content.getChildCount();
    // this must be called before addTab() so that the TabHost searches its TabWidget
    // and FrameLayout.
    tabHost.setup();
    if (count == 0) {
        // Create a dummy child to get a single tab
        TabSpec spec = tabHost.newTabSpec("tag").setIndicator("Tab Label", tabHost.getResources().getDrawable(android.R.drawable.ic_menu_info_details, null)).setContent(new TabHost.TabContentFactory() {

            @Override
            public View createTabContent(String tag) {
                return new LinearLayout(getContext());
            }
        });
        tabHost.addTab(spec);
    } else {
        // for each child of the frameLayout, add a new TabSpec
        for (int i = 0; i < count; i++) {
            View child = content.getChildAt(i);
            String tabSpec = String.format("tab_spec%d", i + 1);
            // child cannot be null.
            @SuppressWarnings("ConstantConditions") int id = child.getId();
            @SuppressWarnings("deprecation") Pair<ResourceType, String> resource = layoutlibCallback.resolveResourceId(id);
            String name;
            if (resource != null) {
                name = resource.getSecond();
            } else {
                // default name if id is unresolved.
                name = String.format("Tab %d", i + 1);
            }
            tabHost.addTab(tabHost.newTabSpec(tabSpec).setIndicator(name).setContent(id));
        }
    }
}
Also used : TabHost(android.widget.TabHost) ResourceType(com.android.resources.ResourceType) TabWidget(android.widget.TabWidget) MenuView(com.android.internal.view.menu.MenuView) View(android.view.View) AdapterView(android.widget.AdapterView) ActionMenuItemView(com.android.internal.view.menu.ActionMenuItemView) IconMenuItemView(com.android.internal.view.menu.IconMenuItemView) ListView(android.widget.ListView) ListMenuItemView(com.android.internal.view.menu.ListMenuItemView) AbsListView(android.widget.AbsListView) ActionMenuView(android.widget.ActionMenuView) ExpandableListView(android.widget.ExpandableListView) TabSpec(android.widget.TabHost.TabSpec) FrameLayout(android.widget.FrameLayout) LinearLayout(android.widget.LinearLayout)

Example 28 with TabHost

use of android.widget.TabHost in project cw-android by commonsguy.

the class TabDemo method onCreate.

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.main);
    TabHost tabs = (TabHost) findViewById(R.id.tabhost);
    tabs.setup();
    TabHost.TabSpec spec = tabs.newTabSpec("tag1");
    spec.setContent(R.id.tab1);
    spec.setIndicator("Clock");
    tabs.addTab(spec);
    spec = tabs.newTabSpec("tag2");
    spec.setContent(R.id.tab2);
    spec.setIndicator("Button");
    tabs.addTab(spec);
}
Also used : TabHost(android.widget.TabHost)

Example 29 with TabHost

use of android.widget.TabHost in project cw-android by commonsguy.

the class IntentTabDemo method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    TabHost host = getTabHost();
    Intent i = new Intent(this, CWBrowser.class);
    i.putExtra(CWBrowser.URL, "http://commonsware.com");
    host.addTab(host.newTabSpec("one").setIndicator("CW").setContent(i));
    i = new Intent(i);
    i.putExtra(CWBrowser.URL, "http://www.android.com");
    host.addTab(host.newTabSpec("two").setIndicator("Android").setContent(i));
}
Also used : TabHost(android.widget.TabHost) Intent(android.content.Intent)

Example 30 with TabHost

use of android.widget.TabHost in project android_frameworks_base by AOSPA.

the class LaunchpadTabActivity method onCreate.

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    Intent tabIntent = new Intent(getIntent());
    tabIntent.setComponent((ComponentName) tabIntent.getParcelableExtra("tab"));
    TabHost th = getTabHost();
    TabHost.TabSpec ts = th.newTabSpec("1");
    ts.setIndicator("One");
    ts.setContent(tabIntent);
    th.addTab(ts);
}
Also used : TabHost(android.widget.TabHost) Intent(android.content.Intent)

Aggregations

TabHost (android.widget.TabHost)73 View (android.view.View)30 Intent (android.content.Intent)21 ViewGroup (android.view.ViewGroup)18 ListView (android.widget.ListView)18 Test (org.junit.Test)17 TabWidget (android.widget.TabWidget)15 AdapterView (android.widget.AdapterView)13 AbsListView (android.widget.AbsListView)12 ExpandableListView (android.widget.ExpandableListView)12 TextView (android.widget.TextView)11 ActionMenuView (android.widget.ActionMenuView)10 ActionMenuItemView (com.android.internal.view.menu.ActionMenuItemView)10 IconMenuItemView (com.android.internal.view.menu.IconMenuItemView)10 ListMenuItemView (com.android.internal.view.menu.ListMenuItemView)10 MenuView (com.android.internal.view.menu.MenuView)10 FrameLayout (android.widget.FrameLayout)7 LinearLayout (android.widget.LinearLayout)7 AbsSpinner (android.widget.AbsSpinner)6 QuickContactBadge (android.widget.QuickContactBadge)6