我正在创建一个自定义tabhost,在每个选项卡上打开不同的活动。我想在子活动上获取标签主机,以便在标签主机屏幕上找到线性布局。
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
个文件。但是我能够在Sever活动中获得标签主机的详细信息。
请建议我使用可用的链接或示例代码。