在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在每个标签内创建一个新的a来容纳文本。这将允许特定于每个选项卡内容的内容包装。

我提供了一个示例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稍作修改。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

ActionBar的标签标题中的自定义字体

来自分类Dev

iOS自定义UITableViewCell设置UIButton标题标签文本

来自分类Dev

在标签标题上设置Android自定义字体

来自分类Dev

无法自定义标签中的android图标和文本

来自分类Dev

如何在标题中进行自定义导航

来自分类Dev

R自定义函数-在标题中包含参数值

来自分类Dev

onsenui在导航标题中添加自定义图像

来自分类Dev

如何在表单标题中创建自定义视图

来自分类Dev

在自定义BigCommerce模具主题中编辑标题脚本

来自分类Dev

如何更改自定义帖子类型的特色图像metabox标题和文本标签?

来自分类Dev

如何更改自定义帖子类型的特色图像metabox标题和文本标签?

来自分类Dev

从自定义标签获取文本

来自分类Dev

在自定义标题栏上设置标题文本

来自分类Dev

Android / Xamarin项目中的自定义主题-Action Bar的中心标题文本

来自分类Dev

Android-自定义后,标题文本未显示在操作栏中

来自分类Dev

是否可以在<a>标签中自定义标题弹出窗口?

来自分类Dev

UITableView 插入行后,更新自定义标题的标签

来自分类Dev

Android标签自定义视图

来自分类Dev

尝试将文本输入设置为每个键中的标签标题后,自定义键盘崩溃

来自分类Dev

为文本框标题应用自定义模板

来自分类Dev

为文本框标题应用自定义模板

来自分类Dev

无法自定义标签页中的android图标和文本

来自分类Dev

Android:使用标签版式的样式设置自定义视图的文本颜色

来自分类Dev

如何通过带有标题中的自定义参数的RestTemplate发送POST请求

来自分类Dev

Prestashop自定义php页面标题中出现404错误

来自分类Dev

如何在自定义控件的标题中添加按钮,以扩展Telerik RadTileViewItem?

来自分类Dev

Prestashop自定义php页面标题中出现404错误

来自分类Dev

将菜单放在带有自定义主题的标题中

来自分类Dev

多选表视图 - 当部分展开/折叠时在自定义标题中旋转图像

Related 相关文章

  1. 1

    ActionBar的标签标题中的自定义字体

  2. 2

    iOS自定义UITableViewCell设置UIButton标题标签文本

  3. 3

    在标签标题上设置Android自定义字体

  4. 4

    无法自定义标签中的android图标和文本

  5. 5

    如何在标题中进行自定义导航

  6. 6

    R自定义函数-在标题中包含参数值

  7. 7

    onsenui在导航标题中添加自定义图像

  8. 8

    如何在表单标题中创建自定义视图

  9. 9

    在自定义BigCommerce模具主题中编辑标题脚本

  10. 10

    如何更改自定义帖子类型的特色图像metabox标题和文本标签?

  11. 11

    如何更改自定义帖子类型的特色图像metabox标题和文本标签?

  12. 12

    从自定义标签获取文本

  13. 13

    在自定义标题栏上设置标题文本

  14. 14

    Android / Xamarin项目中的自定义主题-Action Bar的中心标题文本

  15. 15

    Android-自定义后,标题文本未显示在操作栏中

  16. 16

    是否可以在<a>标签中自定义标题弹出窗口?

  17. 17

    UITableView 插入行后,更新自定义标题的标签

  18. 18

    Android标签自定义视图

  19. 19

    尝试将文本输入设置为每个键中的标签标题后,自定义键盘崩溃

  20. 20

    为文本框标题应用自定义模板

  21. 21

    为文本框标题应用自定义模板

  22. 22

    无法自定义标签页中的android图标和文本

  23. 23

    Android:使用标签版式的样式设置自定义视图的文本颜色

  24. 24

    如何通过带有标题中的自定义参数的RestTemplate发送POST请求

  25. 25

    Prestashop自定义php页面标题中出现404错误

  26. 26

    如何在自定义控件的标题中添加按钮,以扩展Telerik RadTileViewItem?

  27. 27

    Prestashop自定义php页面标题中出现404错误

  28. 28

    将菜单放在带有自定义主题的标题中

  29. 29

    多选表视图 - 当部分展开/折叠时在自定义标题中旋转图像

热门标签

归档