私はtabactivity
5つのタブを持っています。それぞれがクラスを持つ独自の意図を持っています。今私がやろうとしているのは、に含まれていない他のアクティビティに同じタブを配置することですtabhosts
tabspec
。私はAndroidの初心者です。我慢してください。
ホームタブ.java:
public class HomeTab extends TabActivity {
private static final String LOG_TAG = null;
@SuppressWarnings("deprecation")
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.activity_home_tab);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.window_title);
Resources ressources = getResources();
final TabHost tabHost = getTabHost();
Intent intentHome= new Intent().setClass(this, Home.class);
TabSpec tabSpecHome = tabHost
.newTabSpec("Home")
.setIndicator("", ressources.getDrawable(R.drawable.home))
.setContent(intentHome);
Intent intentShopInfo= new Intent().setClass(this, ShopInfo.class);
TabSpec tabSpecShopInfo = tabHost
.newTabSpec("ShopInfo")
.setIndicator("", ressources.getDrawable(R.drawable.home))
.setContent(intentShopInfo);
// Android tab
Intent intentDiscover= new Intent().setClass(this, MainAct.class);
TabSpec tabSpecDiscover = tabHost
.newTabSpec("MainAct")
.setIndicator("", ressources.getDrawable(R.drawable.discover))
.setContent(intentDiscover);
// Apple tab
Intent intentMode = new Intent().setClass(this, Mode.class);
TabSpec tabSpecMode = tabHost
.newTabSpec("Mode")
.setIndicator("", ressources.getDrawable(R.drawable.mode))
.setContent(intentMode);
// Windows tab
Intent intentExplore = new Intent().setClass(this, Explore.class);
TabSpec tabSpecExplore = tabHost
.newTabSpec("Explore")
.setIndicator("", ressources.getDrawable(R.drawable.explore))
.setContent(intentExplore);
Intent intentSearch = new Intent().setClass(this, SearchView.class);
TabSpec tabSpecSearch = tabHost
.newTabSpec("SearchView")
.setIndicator("", ressources.getDrawable(R.drawable.search))
.setContent(intentSearch);
// Blackberry tab
// add all tabs
tabHost.addTab(tabSpecHome);
tabHost.addTab(tabSpecDiscover);
tabHost.addTab(tabSpecExplore);
tabHost.addTab(tabSpecSearch);
tabHost.addTab(tabSpecMode);
for(int i=0;i<tabHost.getTabWidget().getChildCount();i++)
tabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.parseColor("#eb8114")); //unselected
tabHost.setOnTabChangedListener(new OnTabChangeListener() {
@Override
public void onTabChanged(String arg0) {
WifiManager wifi;
wifi=(WifiManager)getSystemService(Context.WIFI_SERVICE);
setTabColor(tabHost);
ConnectionDetector cd = new ConnectionDetector(getApplicationContext());
Boolean isInternetPresent = cd.isConnectingToInternet();
//Checking whether Wifi is on or off
if(isInternetPresent)
{
}
else
{
if(tabHost.getCurrentTab() == 1)
{
Toast.makeText(HomeTab.this,
"No Internet Connection Please Enable Wifi Mode to Enjoy Discover Service " , Toast.LENGTH_LONG)
.show();
tabHost.setCurrentTab(2);
}
}
}
});
}
public void setTabColor(TabHost tabhost) {
for(int i=0;i<tabhost.getTabWidget().getChildCount();i++)
tabhost.getTabWidget().getChildAt(i).setBackgroundColor(Color.parseColor("#eb8114")); //unselected
if(tabhost.getCurrentTab()==0)
{
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.window_title);
}
else if(tabhost.getCurrentTab()==1)
{
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.dis);
}
else if(tabhost.getCurrentTab()==2)
{
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.exp);
}
else if(tabhost.getCurrentTab()==3)
{
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.sea);
}
else if(tabhost.getCurrentTab()==4)
{
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.mod);
}
}
public void Back(View v)
{
Toast.makeText(HomeTab.this,
"No Internet Connection Please Enable Wifi Mode to Enjoy Discover Service " , Toast.LENGTH_LONG)
.show();
}
public void Next(View v)
{
Intent intent = new Intent(HomeTab.this,Dbase.class);
startActivity(intent);
}
}
XML
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="20dp"
android:padding="5dp" />
<TabWidget
android:id="@android:id/tabs"
android:layout_marginTop="20dp"
android:layout_alignParentBottom="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</RelativeLayout>
</TabHost>
</RelativeLayout>
よろしくお願いします。