0

我正在创建一个自定义选项卡主机,在每个选项卡规范上打开不同的活动。我想在子活动上获取选项卡主机,以在选项卡主机屏幕上查找线性布局。

select_item.xml(选项卡主机布局)

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<include
    android:id="@+id/include1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    layout="@layout/outcom_actionbar" >
</include>

<TabHost
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"        
    android:layout_height="fill_parent" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >

        <View
            android:layout_width="fill_parent"
            android:layout_height="0.5dip"
            android:background="#fff" />

        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="0dip"
            android:layout_marginRight="0dip" />

        <View
            android:layout_width="fill_parent"
            android:layout_height="2dip"
            android:background="#696969" />

        <View
            android:layout_width="fill_parent"
            android:layout_height="2dip"
            android:background="#add23b" />

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" />
    </LinearLayout>
</TabHost>

</LinearLayout>

SelectItem.java(自定义选项卡主机)

public class SelectItem extends TabActivity {   

private TabHost mTabHost;

private void setupTabHost() {
    mTabHost = (TabHost) findViewById(android.R.id.tabhost);
    mTabHost.setup();
}

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.select_item);   
    context=this;       

    setupTabHost();
    mTabHost.getTabWidget().setDividerDrawable(null);
    setupTab(new TextView(this), getString(R.string.Positions),Constants.ActivityName.Positions.toString());
    setupTab(new TextView(this), getString(R.string.Sever),Constants.ActivityName.Sever.toString());

}

private void setupTab(final View view, final String tag,final String activityName) {
    View tabview = createTabView(mTabHost.getContext(), tag);

    TabSpec setContent = mTabHost.newTabSpec(tag).setIndicator(tabview).setContent(new TabContentFactory() {
        public View createTabContent(String tag) {return view;}
    });
    Intent  intent =null;
    if(activityName.compareToIgnoreCase(Constants.ActivityName.Positions.toString())==0)        
        intent = new Intent().setClass(this, Items.class);  
    else if(activityName.compareToIgnoreCase(Constants.ActivityName.Sever.toString())==0)
        intent = new Intent().setClass(this, Sever.class);      
    intent.putExtra(Constants.PROJECT_ID, projectId);
    setContent.setContent(intent);
    mTabHost.addTab(setContent);

}

private static View createTabView(final Context context, final String text) {
    View view = LayoutInflater.from(context).inflate(R.layout.tabs_bg, null);
    TextView tv = (TextView) view.findViewById(R.id.tabsText);
    tv.setText(text);
    return view;
}

}

LinearLayout在服务器活动上,我想查看select_item.xml文件。但我能够在服务器活动中获取选项卡主机的详细信息。

请建议我可用的链接或示例代码。

4

1 回答 1

1

这是一个可以帮助您的示例。单击此处 查看链接并在 GitHub 上查看他的项目。它真的帮助了我。

于 2012-06-05T10:26:28.853 回答