[英]Customizing Text in tab title for android
我目前的工作是什么……
我設計了一個標簽活動,底部有四個標簽
快照
BreakfastLunchDinnerIndividualListOfItems.java
public class BreakfastLunchDinnerIndividualListOfItems extends TabActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.breakfast_lunch_dinner_individual_list_of_items);
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, BLD_IndividualListOfItems_Starters.class);
spec = tabHost.newTabSpec("STARTERS").setIndicator("Starters").setContent(intent);
tabHost.addTab(spec);
// Do the same for the other tabs
intent = new Intent().setClass(this, BLD_IndividualListOfItems_MainCourse.class);
spec = tabHost.newTabSpec("MAIN_COURSE").setIndicator("Main Course").setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, BLD_IndividualListOfItems_SideCourse.class);
spec = tabHost.newTabSpec("SIDE_COURSE").setIndicator("Side course").setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, BLD_IndividualListOfItems_Others.class);
spec = tabHost.newTabSpec("OTHERS").setIndicator("Others").setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, BLD_IndividualListOfItems_Desert.class);
spec = tabHost.newTabSpec("DESERT").setIndicator("Deserts").setContent(intent);
tabHost.addTab(spec);
//set tab which one you want open first time 0 or 1 or 2
tabHost.setCurrentTab(0);
}
}
breakfast_lunch_dinner_individual_list_of_items.java
<?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">
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"/>
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:layout_marginBottom="-4dp"/>
</LinearLayout>
</TabHost>
問題 ::
我正在努力實現的目標 ::
當您在標簽小部件中定義layout_width="fill_parent"
時,就是說所有標簽的尺寸均等,並填充其各自的父標簽。 但是,對於您而言,這些標簽內的內容不能保證是均勻的。 因此,您需要在每個標簽內創建一個新的TextView
來容納文本。 這將允許特定於每個選項卡內容的內容包裝。
我提供了一個示例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">
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"/>
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:layout_marginBottom="-4dp">
<TextView
android:tag="tab0"
android:text="Starters"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
/>
<TextView
android:tag="tab1"
android:text="Main Course"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
/>
<TextView
android:tag="tab2"
android:text="Side Course"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
/>
<TextView
android:tag="tab2"
android:text="Others"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
/>
<TextView
android:tag="tab2"
android:text="Desert"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
/>
</TabWidget>
</LinearLayout>
我相信這也將需要對Java稍作修改。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.