2013-06-18 5 views
0

학습 목적으로 Android에 매우 간단한 Tab Host 데모를 구성했습니다. 여기에 설명되어 있습니다 : http://www.androidhub4you.com/2013/04/android-tabactivity-tab-layout-demo-tab.html탭 호스트 활동이 Android에서 작동하지 않습니다.

위의 단계를 수행했지만 작동하지 않습니다. 도와주세요. 내 코드는 다음과 같습니다

TabhostActivity.java

package com.example.tabhostdemo; 

import android.os.Bundle; 
import android.app.Activity; 
import android.app.TabActivity; 
import android.content.Intent; 
import android.content.res.Resources; 
import android.view.Menu; 
import android.widget.TabHost; 


public class TabHostActivity extends TabActivity { 


    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_tab_host); 
     Resources res = getResources(); // Resource object to get Drawables 
     TabHost tabHost = getTabHost(); // The activity TabHost 
     TabHost.TabSpec spec; // Reusable TabSpec for each tab 
     Intent intent; // Reusable Intent for each tab 

     // Create an Intent to launch an Activity for the tab (to be reused) 
     intent = new Intent().setClass(this, HomeActivity.class); 
     spec = tabHost.newTabSpec("home") 
     .setIndicator("HOME", res.getDrawable(R.drawable.home1)) 
     .setContent(intent); 
     tabHost.addTab(spec); 

     // Do the same for the other tabs 

     intent = new Intent().setClass(this, AboutActivity.class); 
     spec = tabHost.newTabSpec("about") 
     .setIndicator("ABOUT", res.getDrawable(R.drawable.about1)) 
     .setContent(intent); 
     tabHost.addTab(spec); 


     intent = new Intent().setClass(this, ContactActivity.class); 
     spec = tabHost 
     .newTabSpec("contact") 
     .setIndicator("CONTACT", 
     res.getDrawable(R.drawable.contact1)) 
     .setContent(intent); 
     tabHost.addTab(spec); 

     //set tab which one you want open first time 0 or 1 or 2 
     tabHost.setCurrentTab(0); 


     } 

     } 

/Drawable/home.xml

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <!-- When selected --> 
    <item android:drawable="@drawable/home1" 
      android:state_selected="true" /> 
    <!-- When not selected--> 
    <item android:drawable="@drawable/home2" /> 
</selector> 

/Drawable/contact.xml

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <!-- When selected --> 
    <item android:drawable="@drawable/contact1" 
      android:state_selected="true" /> 
    <!-- When not selected--> 
    <item android:drawable="@drawable/contact2" /> 
</selector> 

/Drawable/about.xml

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <!-- When selected --> 
    <item android:drawable="@drawable/about1" 
      android:state_selected="true" /> 
    <!-- When not selected--> 
    <item android:drawable="@drawable/about2" /> 
</selector> 
+0

tabhost가 http://developer.android.com/reference/android/support/v4/app/FragmentTabHost.html – abhi

+0

처럼 FragmentTabHost 사용하려고하십시오 depricated되는'TabHost'이되지되지 않습니다. 어떻게 * 작동하지 않는 *? – Luksprog

+0

'TabActivity' 이 (가) 박탈되었습니다. –

답변

관련 문제