Java Code Examples for android.widget.TabHost#addView()

The following examples show how to use android.widget.TabHost#addView() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PdDroidParty.java    From PdDroidPublisher with GNU General Public License v3.0 6 votes vote down vote up
public static TabHost createTabHost(Context context) {
    // Create the TabWidget (the tabs)
    TabWidget tabWidget = new TabWidget(context);
    tabWidget.setId(android.R.id.tabs);

    // Create the FrameLayout (the content area)
    FrameLayout frame = new FrameLayout(context);
    frame.setId(android.R.id.tabcontent);
    LinearLayout.LayoutParams frameLayoutParams = new LinearLayout.LayoutParams(
        LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT, 1);
    frameLayoutParams.setMargins(4, 4, 4, 4);
    frame.setLayoutParams(frameLayoutParams);

    // Create the container for the above widgets
    LinearLayout tabHostLayout = new LinearLayout(context);
    tabHostLayout.setOrientation(LinearLayout.VERTICAL);
    tabHostLayout.addView(tabWidget);
    tabHostLayout.addView(frame);

    // Create the TabHost and add the container to it.
    TabHost tabHost = new TabHost(context, null);
    tabHost.addView(tabHostLayout);
    tabHost.setup();

    return tabHost;
}
 
Example 2
Source File: IMPopupDialog.java    From opensudoku with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates view with two tabs, first for number in cell selection, second for
 * note editing.
 *
 * @return
 */
private TabHost createTabView() {
    TabHost tabHost = new TabHost(mContext, null);
    tabHost.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
    //tabHost.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

    LinearLayout linearLayout = new LinearLayout(mContext);
    linearLayout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
    //linearLayout.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    linearLayout.setOrientation(LinearLayout.VERTICAL);

    TabWidget tabWidget = new TabWidget(mContext);
    tabWidget.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
    tabWidget.setId(android.R.id.tabs);

    FrameLayout frameLayout = new FrameLayout(mContext);
    frameLayout.setId(android.R.id.tabcontent);

    linearLayout.addView(tabWidget);
    linearLayout.addView(frameLayout);
    tabHost.addView(linearLayout);

    tabHost.setup();

    final View editNumberView = createEditNumberView();
    final View editNoteView = createEditNoteView();

    tabHost.addTab(tabHost.newTabSpec("number")
            .setIndicator(mContext.getString(R.string.select_number))
            .setContent(tag -> editNumberView));
    tabHost.addTab(tabHost.newTabSpec("note")
            .setIndicator(mContext.getString(R.string.edit_note))
            .setContent(tag -> editNoteView));

    return tabHost;
}