Android 如何在我的整个应用程序屏幕中显示tabbar?它会在下一个活动中消失
安卓 我已经在android的底部创建了Tabbar。它在一个屏幕上运行良好,但当我转到另一个活动时,它就会消失Android 如何在我的整个应用程序屏幕中显示tabbar?它会在下一个活动中消失,android,tags,Android,Tags,安卓 我已经在android的底部创建了Tabbar。它在一个屏幕上运行良好,但当我转到另一个活动时,它就会消失 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)
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);
你必须在tabhost中使用你的活动,不要独立启动活动你只将tabbar分配给了一个活动,因此很明显,它将在其他活动中消失。所以,你必须在每项活动上都放上标签栏。我要做的是将tabbar放在一个单独的XML文件中,例如layout/tabbar.XML。。。并在其他XML布局上使用标记,以避免重复同一代码两次或两次以上。试试看
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);
}
使用此选项启动新活动
View view = getLocalActivityManager().startActivity("tab1", new Intent(this,tab1.class)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
.getDecorView();
setContentView(view);
是的,伙计,我尝试了上面的代码,它工作得很好,但我需要更多的细节。去吧,别忘了提我的观点,thxye dude我尝试了上面的代码,效果很好,但我需要更多的细节。我在我的应用程序的底部有一个五个选项卡。我直接从登录屏幕调用tabactivity,这样它就会显示登录页面的活动。当我单击一个选项卡时,它会打开它的设置活动,但在它的可设置活动中,tabar会消失。帮我处理它的紧急情况…帮助