[英]Tabs not showing in the Fragment Activity
I am trying to put a tab host in a fragment activity, i made a custom layout to hold the tabs and put that view int the setIndicator of the tabhost but unfortunately the tabs are not showing ...... can anybody help... 我试图将选项卡宿主放在片段活动中,我制作了一个自定义布局来容纳选项卡,并将该视图放入选项卡宿主的setIndicator中,但是不幸的是,这些选项卡未显示......任何人都可以帮忙.. 。
public class MainActivity extends FragmentActivity {
private FragmentTabHost mTabHost;
LayoutInflater inflater;
View tabdesign, tabSplitter;
AddFragment addfragment;
private ImageView label;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
//check configuration
// Configuration config = getResources().getConfiguration();
//setting up tabs
tabdesign = inflater.inflate(R.layout.inside_tab_design, null);
mTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost);
mTabHost.setup(this, getSupportFragmentManager(), R.id.content);
inflater = (LayoutInflater) getBaseContext().getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
label=(ImageView)tabdesign.findViewById(R.id.tablabel);
label.setImageResource(R.drawable.settings);
mTabHost.addTab(mTabHost.newTabSpec("tab1").setIndicator(tabdesign),
SmallFragment.class, null);
tabSplitter = (View) tabdesign.findViewById(R.id.tabSplitter);
tabdesign = inflater.inflate(R.layout.inside_tab_design, null);
label = (ImageView) tabdesign.findViewById(R.id.tablabel);
label.setImageResource(R.drawable.settings);
mTabHost.addTab(mTabHost.newTabSpec("tab2").setIndicator(tabdesign),
TabeFragment.class, null);
}
}
this is my main xml: 这是我的主要xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@android:color/black">
<FrameLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</FrameLayout>
<android.support.v4.app.FragmentTabHost
android:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="52dp" >
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="0" />
</android.support.v4.app.FragmentTabHost>
</LinearLayout>
this is my custom tab layout view: 这是我的自定义标签布局视图:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tab"
android:layout_width="match_parent"
android:layout_height="52dp"
android:background="#898989"
android:orientation="vertical" >
<View
android:id="@+id/tabSplitter"
android:layout_width="1dip"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:background="#ffffff" />
<ImageView
android:id="@+id/tablabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
/>
</RelativeLayout>
Try this out: 试试看:
<android.support.v4.app.FragmentTabHost
android:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="52dp" >
<TabWidget android:id="@android:id/tabs"
android:layout_height="wrap_content"
android:layout_width="fill_parent"/>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="0" />
</android.support.v4.app.FragmentTabHost>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.