【问题标题】:Custom tabs in android [closed]android中的自定义标签[关闭]
【发布时间】:2010-10-11 05:58:24
【问题描述】:

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

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

【问题讨论】:

    标签: android android-tabhost


    【解决方案1】:

    您可以在 /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);
    }
    

    【讨论】:

    • 你能在tab_layout.xml文件中显示一些设置文本和图像吗?
    • 这样,我们需要自己处理每个选项卡的选中、按下等状态。对吗?
    • tab_layout 和 layout 有什么区别。我的意思是我的布局应该有什么价值?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-13
    • 2014-05-23
    • 2011-04-24
    • 1970-01-01
    • 2011-08-31
    相关资源
    最近更新 更多