tabSpace上的spec.setContent(Intent)时出错

时间:2017-01-18 13:12:19

标签: android-tabhost

我在TabSpace上将Intent作为spec.setContent(Intent);时出错,如果我在spec.setContent(tab1);上放置一个布局,它会正常工作

以下是错误: -

  

你忘了打电话'public void setup(localactivitymanager   的ActivityGroup)

这是班级: -

public class test extends AppCompatActivity {

    Point size;
    RelativeLayout r1;
    CallbackManager callbackManager;
    Context context;
    TabHost.TabSpec spec_signin,spec_signup;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.main);

        context = getApplicationContext();

       Display display = getWindowManager().getDefaultDisplay();
        size = new Point();
        display.getSize(size);
        Bitmap bmp = Bitmap.createScaledBitmap(BitmapFactory.decodeResource(
                getResources(),R.drawable.accont_bannre),size.x,size.y,true);
        Drawable dr = new BitmapDrawable(bmp);
        r1 = (RelativeLayout)findViewById(R.id.r1);
        r1.setBackgroundDrawable(dr);

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

        //Tab 1
        spec_signin = host.newTabSpec("SIGNIN");
        Intent songsIntent = new Intent(this, NotificationActivity.class);
        spec_signin.setContent(songsIntent);
        spec_signin.setIndicator("SIGN IN", getResources().getDrawable(R.drawable.active_arrow));
      //  spec_signin.setIndicator("SIGNIN");
         host.addTab(spec_signin);

        //Tab 2
        spec_signup = host.newTabSpec("SIGNUP");
        Intent Intent = new Intent(this, NotificationActivity.class);
        spec_signup.setContent(Intent);
        spec_signup.setIndicator("SIGN UP", getResources().getDrawable(R.drawable.active_arrow));
        // spec_signup.setIndicator("SIGNUP");
        host.addTab(spec_signup);

    }//oncreate ends
}

和XML: - <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <TabHost android:id="@+id/tabhost" android:layout_width="fill_parent" android:layout_height="wrap_content"> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/r2"> <RelativeLayout android:id="@+id/r1" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="270dp"> <LinearLayout android:layout_alignParentBottom="true" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="wrap_content"> <View android:layout_above="@+id/tabs" android:id="@+id/v1" android:layout_width="match_parent" android:layout_height="1dp" android:background="#ccc7c7"/> <TabWidget android:id="@android:id/tabs" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </LinearLayout> </RelativeLayout> <FrameLayout android:background="#dede" android:layout_below="@+id/r1" android:id="@android:id/tabcontent" android:layout_width="fill_parent" android:layout_height="match_parent"> </FrameLayout> </RelativeLayout> </TabHost> </RelativeLayout> `

1 个答案:

答案 0 :(得分:0)

我添加了以下行并且正在运行。

LocalActivityManager mLocalActivityManager = new LocalActivityManager(this, false);
    mLocalActivityManager.dispatchCreate(savedInstanceState);

    host.setup(mLocalActivityManager);