【问题标题】:Tabhost not appear when open new activity out Side of the tab在选项卡侧面打开新活动时不显示选项卡主机
【发布时间】:2014-01-03 19:41:27
【问题描述】:

这是我的代码

View view = getLocalActivityManager().startActivity("recently_viewd", 
                        new Intent(context,Job_Description.class)
                  .putExtra("line", result)
                    .putExtra("limit",0)
                    .putExtra("Alert", false)
                    .putExtra("str_Descrption",edit_Jobdesc.getText().toString().trim())
                    .putExtra("str_location", edit_JobLoc.getText().toString().trim()).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
                        .getDecorView();

                setContentView(view);

TabActiviy.class

public class Tab_Bar extends TabActivity  {

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.tab);
    setTabs() ;
}
 void setTabs()
{
    addTab("My Profile", R.drawable.home_normal, MyProfile.class);
    addTab("Search", R.drawable.search_normal, JobSearch.class);

    addTab("Saved Jobs", R.drawable.starred, Saved_jobs.class);
    addTab("Job Alert", R.drawable.job_match, JobAlert.class);
}

private void addTab(String labelId, int drawableId, Class<?> c)
{
    TabHost tabHost = getTabHost();
    Intent intent = new Intent(this, c);
    TabHost.TabSpec spec = tabHost.newTabSpec("tab" + labelId); 

    View tabIndicator = LayoutInflater.from(this).inflate(R.layout.tab_indicator, getTabWidget(), false);
    TextView title = (TextView) tabIndicator.findViewById(R.id.title);
    title.setText(labelId);
    ImageView icon = (ImageView) tabIndicator.findViewById(R.id.icon);
    icon.setImageResource(drawableId);

    spec.setIndicator(tabIndicator);
    spec.setContent(intent);
    tabHost.addTab(spec);
    tabHost.setCurrentTab(1);

}

}

我正在使用此代码在 TabHost 中打开新活动。 Activity 已打开,但 Tabhost 未出现

请帮我解决这个问题

提前致谢

【问题讨论】:

  • 不可能用这么少的代码指出你的错误。使用 tabhost 声明发布更多代码。
  • 我没有收到任何错误,此代码用于在 tabHost 中打开新活动
  • 这对我来说非常重要,我是 android 新手,请查看我的问题并给我一个解决问题的建议

标签: android android-fragments android-tabs android-tabactivity


【解决方案1】:
 public class Tab_Bar extends TabActivity  {
  TabHost tabHost;
 public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tab);
tabHost = getTabHost();
tabHost.setup();
setTabs() ;
}
 void setTabs()
{
addTab("My Profile", R.drawable.home_normal, MyProfile.class);
addTab("Search", R.drawable.search_normal, JobSearch.class);

addTab("Saved Jobs", R.drawable.starred, Saved_jobs.class);
addTab("Job Alert", R.drawable.job_match, JobAlert.class);
}

private void addTab(String labelId, int drawableId, Class<?> c)
{

Intent intent = new Intent(this, c);
TabHost.TabSpec spec = tabHost.newTabSpec("tab" + labelId); 

View tabIndicator = LayoutInflater.from(this).inflate(R.layout.tab_indicator, getTabWidget(), false);
TextView title = (TextView) tabIndicator.findViewById(R.id.title);
title.setText(labelId);
ImageView icon = (ImageView) tabIndicator.findViewById(R.id.icon);
icon.setImageResource(drawableId);

spec.setIndicator(tabIndicator);
spec.setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(1);

 }

 }

【讨论】:

  • 感谢重播,那么我该如何解决这个问题
  • 我不想在标签栏上添加活动,我想简单的打开活动,但旧小部件也可以使用标签栏
  • 我没有让你感到抱歉。简而言之,请
  • 我在标签栏中添加了四个类(A、B、C、D),现在我想打开 E 类表单 F。并想显示带有四个类(A、B、 C,D)
  • 我们如何改变我是android新手所以我没有想法请给我一个例子
猜你喜欢
  • 1970-01-01
  • 2019-12-30
  • 2017-08-08
  • 1970-01-01
  • 1970-01-01
  • 2021-11-23
  • 1970-01-01
  • 2020-08-30
  • 1970-01-01
相关资源
最近更新 更多