开发者

how to show tabbar in my whole application screen? it disappears in next activity

开发者 https://www.devze.com 2023-02-28 18:57 出处:网络
Android I have created Tabbar in bottom side in android. It works well开发者_运维百科 for one screen but when Imove to anther activity it disappears.host= (TabHost)findViewById(android.R.id.tabhost);

Android

I have created Tabbar in bottom side in android. It works well开发者_运维百科 for one screen but when I move to anther activity it disappears.


host= (TabHost)findViewById(android.R.id.tabhost);
        host.setup();


        TabHost.TabSpec spec;

        // Create an Intent to launch the first Activity for the tab (to be reused)  
        Intent i = new Intent().setClass(this, activity1.class);  

        spec = host.newTabSpec ("FirstGroup").setIndicator("activity1",getResources().getDrawable(R.drawable.imagename)).setContent(i);  

        host.addTab(spec);  
 TabHost.TabSpec spec;


        // Create an Intent to launch the first Activity for the tab (to be reused)  
        Intent i = new Intent().setClass(this, activity2.class);  

        spec = host.newTabSpec ("FirstGroup").setIndicator("activity2",getResources().getDrawable(R.drawable.imagename)).setContent(i);  

        host.addTab(spec);  

u have to use your activity in tabhost, dont start activity independently


You assigned the tabbar to one activity only, so it's obvious it will disappear for the rest of the activities. So, you have to put the tab bar stuff on each activity. What I'd do is putting the tabbar on a separate XML file (e.g. layout/tabbar.xml)... and use the <include> tag on the other XML layouts in order to avoid repeating the same code twice or more.


Try it

        public class Tab1ActivityGroup extends ActivityGroup
    {
        public static Tab1ActivityGroup group1;
        @Override
        protected void onCreate(Bundle savedInstanceState)
        {

            group1 = this;

            View view = getLocalActivityManager()
                .startActivity("Tab1Activity", new Intent(this, Tab1Activity.class)
                .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
                .getDecorView();

            replaceView(view);
        }

        public void replaceView(View v)
        {
            v.setFocusable(true);
            v.setFocusableInTouchMode(true);
            v.requestFocus();

            setContentView(v);
        }
    }




public class Tab1Activity extends Activity
{

    @Override
    protected void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tab_one_activity);

    }


        View v = Tab1ActivityGroup.group1.getLocalActivityManager()
                    .startActivity("NewActivityFromTabActivity", intent)
                    .getDecorView();
        Tab1ActivityGroup.group.replaceView(v);

}


Use THis to start the new Activity

View view = getLocalActivityManager().startActivity("tab1", new Intent(this,tab1.class)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
.getDecorView();

setContentView(view);
0

精彩评论

暂无评论...
验证码 换一张
取 消