1

我进行了搜索,似乎可以找到任何与我遇到的问题相近的东西,所以我想我会问。我有一个仪表板布局

在此处输入图像描述

这一切正常

我想要做的是让它如下所示工作(我定义了 Tabhost,但我必须设置类来扩展 TabActivity,这会破坏 ActionBar 导航)

在此处输入图像描述

选项卡正确切换,但它不允许我使用操作栏上的任何按钮,并且它没有像应有的那样正确提取信息

在此处输入图像描述

以上工作正常。所以我想我的问题是如何正确地将 TabHost 添加到我的类中并让它扩展或实现仪表板代码?我尝试过扩展 TabActivity 实现仪表板但没有运气。

到目前为止,这是我的代码

仪表板.java

 package com.ondrovic.bbym;

 import android.app.Activity;
 import android.content.Context;
 import android.content.Intent;
 import android.content.res.Configuration;
 import android.os.Bundle;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.LinearLayout;
 import android.widget.TextView;

 public abstract class Dashboard extends Activity {
 public static final boolean usePrettyGoodSolution = false;

 protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
 }

public void onDestroy() {
    super.onDestroy();
}

public void onPause() {
    super.onPause();
}

public void onRestart() {
    super.onRestart();
}

public void onResume() {
    super.onResume();
}

public void onStart() {
    super.onStart();
}

public void onStop() {
    super.onStop();
}

public void onClickHome(View v) {
    goHome(this);
}

public void onClickUpdate(View v) {
    //startActivity(new Intent(getApplicationContext(), Update.class));
}

public void onClickAbout(View v) {
    //startActivity(new Intent(getApplicationContext(), About.class));
}

public void goHome(Context context) {
    final Intent intent = new Intent(context, Home.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    context.startActivity(intent);
}

@Override
public void setContentView(int layoutID) {
    if (!usePrettyGoodSolution) {
        super.setContentView(layoutID);
        return;
    }

    Configuration c = getResources().getConfiguration();
    int size = c.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK;
    boolean isLarge = (size == Configuration.SCREENLAYOUT_SIZE_LARGE);
    boolean isXLarge = (size == Configuration.SCREENLAYOUT_SIZE_XLARGE);
    boolean addFrame = isLarge || isXLarge;

    // if (isLarge) System.out.println ("Large screen");
    // if (isXLarge) System.out.println ("XLarge screen");

    int finalLayoutId = addFrame ? R.layout.large : layoutID;
    super.setContentView(finalLayoutId);

    if (addFrame) {
        LinearLayout frameView = (LinearLayout) findViewById(R.id.frame);
        if (frameView != null) {

            // If the frameView is there, inflate the layout given as an
            // argument.
            // Attach it as a child to the frameView.
            LayoutInflater li = ((Activity) this).getLayoutInflater();
            View childView = li.inflate(layoutID, null);
            if (childView != null) {
                LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
                        ViewGroup.LayoutParams.MATCH_PARENT,
                        ViewGroup.LayoutParams.MATCH_PARENT, 1.0F);
                frameView.addView(childView, lp);
                // childView.setBackgroundResource (R.color.background1);
            }

        }
    }
}

public void setTitleFromActivityLabel(int textViewID) {
    TextView tv = (TextView) findViewById(textViewID);
    if (tv !=null) {
        tv.setText(getTitle());
    }
}

}

个人.java

 package com.ondrovic.bbym;

 import android.app.TabActivity;
 import android.content.Intent;
 import android.os.Bundle;
 import android.widget.TabHost;
 import android.widget.TabHost.TabSpec;

public class Individual extends TabActivity {
public void onCreate(Bundle savedSate) {
    super.onCreate(savedSate);
    setContentView(R.layout.individual);

    TabHost tabHost = getTabHost();
    TabSpec attspec = tabHost.newTabSpec("ATT");
    attspec.setIndicator("AT&T", getResources().getDrawable(R.drawable.icons_att_tab));
    Intent attIntent = new Intent(this, Individual_ATT.class);
    attspec.setContent(attIntent);

    TabSpec sprspec = tabHost.newTabSpec("SPRINT");
    sprspec.setIndicator("SPRINT", getResources().getDrawable(R.drawable.icons_sprint_tab));
    Intent sprIntent = new Intent(this, Individual_SPRINT.class);
    sprspec.setContent(sprIntent);

    TabSpec vzwspec = tabHost.newTabSpec("VERIZON");
    vzwspec.setIndicator("VERIZON", getResources().getDrawable(R.drawable.icons_verizon_tab));
    Intent vzwIntent = new Intent(this, Individual_VERIZON.class);
    vzwspec.setContent(vzwIntent);

    tabHost.addTab(attspec);

    tabHost.addTab(sprspec);

    tabHost.addTab(vzwspec);
}
 }

这是我的个人.xml

 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 android:background="@color/background1"
 android:orientation="vertical" >

 <include layout="@layout/title_bar" />
 <include layout="@layout/tabs" />
 </LinearLayout>

如果有任何其他代码需要发布,请告诉我并感谢您的帮助

4

1 回答 1

0

所以我通过执行以下操作弄清楚了。即使这里可能有更好的方法是我所拥有的

个人.java

 package com.ondrovic.bbym;

 import android.app.LocalActivityManager;
 import android.content.Intent;
 import android.os.Bundle;
 import android.widget.TabHost;
 import android.widget.TabHost.TabSpec;

 public class Individual extends Dashboard {
     TabHost mTabs;
     protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.individual);
    setTitleFromActivityLabel(R.id.title_text);

    mTabs = (TabHost) findViewById(android.R.id.tabhost);
    LocalActivityManager mLocalActivityManager = new LocalActivityManager(this, false);
    mLocalActivityManager.dispatchCreate(savedInstanceState);
    mTabs.setup(mLocalActivityManager);

    TabSpec attspec = mTabs.newTabSpec("ATT");
    attspec.setIndicator("AT&T", getResources().getDrawable(R.drawable.icons_att_tab));
    Intent attIntent = new Intent(this, Individual_ATT.class);
    attspec.setContent(attIntent);

    TabSpec sprintspec = mTabs.newTabSpec("SPRINT");
    sprintspec.setIndicator("SPRINT", getResources().getDrawable(R.drawable.icons_sprint_tab));
    Intent sprintIntent = new Intent(this, Individual_SPRINT.class);
    sprintspec.setContent(sprintIntent);

    TabSpec verizonspec = mTabs.newTabSpec("VERIZON");
    verizonspec.setIndicator("VERIZON", getResources().getDrawable(R.drawable.icons_verizon_tab));
    Intent verizonIntent = new Intent(this, Individual_ATT.class);
    verizonspec.setContent(verizonIntent);

    mTabs.addTab(attspec);
    mTabs.addTab(sprintspec);
    mTabs.addTab(verizonspec);
}
}

这是一切正常的结果:-)

在此处输入图像描述

于 2012-04-14T00:34:24.670 回答