12

我很难理解如何在 android 中使用自定义选项卡。我不想仅仅能够设置文本和东西。我怎样才能改变大小,图像,以及所有这些。

我用谷歌搜索,我找不到任何有意义的东西

4

1 回答 1

26

您可以在 /res/layout.xml 中创建 XML 布局文件。然后你需要在视图中膨胀布局并设置指标。我在我的项目中使用此代码:

private static View prepareTabView(Context context, int textId, int drawable) {
    View view = LayoutInflater.from(context).inflate(R.layout.tab_layout, null);
    // setting text and image
    // ...
    // Write your own code here
    return view;
}

public static void addTab(TabHost host, int title, String tag, int drawable, int layout) {
    TabHost.TabSpec spec = host.newTabSpec(tag);
    spec.setContent(layout);
    View view = prepareTabView(host.getContext(), title, drawable);
    spec.setIndicator(view);
    host.addTab(spec);
}
于 2010-10-11T06:49:37.600 回答