android中的自定义标签 [英] Custom tabs in android

查看:38
本文介绍了android中的自定义标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难理解如何在 android 中使用自定义标签.我不想只是能够设置文本和东西.我怎样才能改变大小、图像等等.

I'm having a really hard time understanding how to use custom tabs in android. I don't want to just be able to set the text and stuff. How can I change the size, and the image, and all that.

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

I've googled and I can't find anything that makes sense

推荐答案

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

You can create XML layout file in /res/layout. Then you need inflate layout in View and set indicator. I use this code in my projects:

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);
}

这篇关于android中的自定义标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆