选项卡未显示在片段活动中

时间:2014-01-22 08:53:37

标签: java android android-fragmentactivity

我正在尝试将标签主机放入片段活动中, 我做了一个自定义布局来保存选项卡并将该视图放在tabhost的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);

     }

}

这是我的主要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>

这是我的自定义标签布局视图:

<?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>

1 个答案:

答案 0 :(得分:0)

试试这个:

<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>