Tab bar not showing when call new activity

只谈情不闲聊 提交于 2020-01-06 04:26:04

问题


My code

 View view = getLocalActivityManager().startActivity("main_jobs", 
                        new Intent(context,Job_Description.class)
                        .putExtra("line", str_line).putExtra("limit",str_limit)
                        .putExtra("limit",""+0)
                        .putExtra("Alert", false)
                        .putExtra("str_location", str_loc)
                        .putExtra("str_Descrption",str_descjob)
                        .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
                        .getDecorView();
                                              setContentView(view);

I am using this code to open new activity with tab but tab bar not showing and not any error get please help me how we can show tab bar to open new activity

Thanks in Advance


回答1:


Sample Example : Consider three tabs here First in MainActivity.java

public class MainActivity extends TabActivity {

    private static final String TAB1 = "TAB1";
    private static final String TAB2 = "TAB2";
    private static final String TAB3 = "TAB3";

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        TabHost tabHost = getTabHost();


        TabSpec tab1 = tabHost.newTabSpec(TAB1);
        tab1.setIndicator(TAB1);
        Intent Intent1 = new Intent(this, Tab1.class);
        tab1.setContent(Intent1);


        TabSpec tab2 = tabHost.newTabSpec(TAB2);
        tab2.setIndicator(TAB2);
        Intent Intent2 = new Intent(this, Tab2.class);
        tab2.setContent(Intent2);


        TabSpec tab3 = tabHost.newTabSpec(TAB3);
        tab3.setIndicator(TAB3);
        Intent Intent3 = new Intent(this, Tab3.class);
        tab1.setContent(Intent3);


        tabHost.addTab(tab1); 
        tabHost.addTab(tab2); 
        tabHost.addTab(tab3); 
    }
}

main.xml

<?xml version="1.0" encoding="utf-8"?>
<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:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">

        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="64dp" />

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

Then three classes Tab1.java , Tab2.java and Tab3.java And three xml files to that classes.

try it out and say.




回答2:


When you are moving to a new activity you are building a whole new view which means that the view you where just on gets thrown out and replaced with this new one. If you want the tab bar you need to build it into this new activity like you did for the first activity.



来源:https://stackoverflow.com/questions/20897268/tab-bar-not-showing-when-call-new-activity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!