android中的自定义标签

Fal*_*rri 12 android android-tabhost

我很难理解如何在android中使用自定义选项卡.我不想只是能够设置文本和东西.如何更改大小,图像以及所有内容.

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

Ser*_*tov 26

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

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);
}
Run Code Online (Sandbox Code Playgroud)