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);
}
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));
}
}
}
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);
}
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));
}
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);
}
Aggregations