2
好吧,所以我正在製作一個具有選項卡的Android應用程序,現在我的問題是選項卡widget在不同的android版本或設備上不統一。 我想使之成爲在任何Android一樣,這是我的標籤活動自定義TabWidget Android選項卡指標
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
public class Cook extends TabActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.cook_layout);
TabHost tabHost = getTabHost();
// Tab for Snacks
TabSpec snackspec = tabHost.newTabSpec("Snacks");
// setting Title and Icon for the Tab
snackspec.setIndicator("Snacks", getResources().getDrawable(R.drawable.cook_icon_tab_snacks));
Intent snacksIntent = new Intent(this, Cook_tab_snacks.class);
snackspec.setContent(snacksIntent);
// Tab for Mains
TabSpec mainspec = tabHost.newTabSpec("Mains");
mainspec.setIndicator("Mains", getResources().getDrawable(R.drawable.cook_icon_tab_snacks));
Intent mainsIntent = new Intent(this, Cook_tab_mains.class);
mainspec.setContent(mainsIntent);
// Tab for Desserts
TabSpec dessertspec = tabHost.newTabSpec("Desserts");
dessertspec.setIndicator("Desserts", getResources().getDrawable(R.drawable.cook_icon_tab_snacks));
Intent dessertsIntent = new Intent(this, Cook_tab_desserts.class);
dessertspec.setContent(dessertsIntent);
// Adding all TabSpec to TabHost
tabHost.addTab(snackspec); // Adding snacks tab
tabHost.addTab(mainspec); // Adding mains tab
tabHost.addTab(dessertspec); // Adding desserts tab
}
}
我也有我的XML佈局:
<?xml version="1.0" encoding="UTF-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<FrameLayout
android:id="@android:id/tabcontent"
android:background="@drawable/gradient_bg"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>
我做了一個新的指標XML這就好比主要安卓標籤指標v4 我跟蹤和搜索了很多的博客,我找不到我的答案... 我真的想在所有的Android版本製作Android標籤統一,並使顏色很好,因爲橙色和黃色不要在我的應用中非常適合顏色主題請幫忙!!!! 我似乎無法找到解決辦法... 乾杯