制作自定义选项卡按钮 [英] Making custom tab buttons

查看:176
本文介绍了制作自定义选项卡按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何得到我的标签按钮,看起来像

How do I get my tab buttons to look like

什么是做到这一点的最简单的方式,如果我在那个形状有绘制过???

What would be the simplest way to do this if I have a drawable in that shape too???

推荐答案

只是可以实现标签到你的应用程序像这样

simply you can implement tabs to your application like this

在onCreate方法

in onCreate method

TabHost tabHost = getTabHost();
tabHost.setCurrentTabByTag("First");

TabSpec firstTab = tabHost.newTabSpec("First");  
firstTab.setIndicator("firstTab",getResources().getDrawable(R.drawable.ic_action_first)); //drawable 1
firstTab.setContent(R.id.first_content);    //View
tabHost.addTab(firstTab);

TabSpec secondTab = tabHost.newTabSpec("Second");
secondTab.setIndicator("secondTab",getResources().getDrawable(R.drawable.ic_action_second)); //drawable 2
secondTab.setContent(R.id.second_content);    //View
tabHost.addTab(secondTab);

TabSpec thirdTab = tabHost.newTabSpec("Third");
thirdTab.setIndicator("thirdTab",getResources().getDrawable(R.drawable.ic_action_third)); //drawable 3
thirdTab.setContent(R.id.third_content);    //View
tabHost.addTab(thirdTab);

tabHost.setCurrentTab(0);

在xml文件

<TabHost android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/tabhost">
    <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical">
        <TabWidget android:id="@android:id/tabs" android:layout_width="fill_parent" android:layout_height="wrap_content" />
        <FrameLayout android:id="@android:id/tabcontent" android:layout_width="wrap_content" android:layout_height="wrap_content" >

            <LinearLayout android:id="@+id/first_content" android:layout_width="fill_parent" android:layout_height="fill_parent">
                <TextView android:text="first_tab"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
            </LinearLayout>

            <LinearLayout android:id="@+id/second_content" android:layout_width="fill_parent" android:layout_height="fill_parent">
                <TextView android:text="second_tab"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
            </LinearLayout>

            <LinearLayout android:id="@+id/third_content" android:layout_width="fill_parent" android:layout_height="fill_parent">
                <TextView android:text="third_tab"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
            </LinearLayout>
        </FrameLayout>

    </LinearLayout>
    </TabHost>

打电话给你在getResources绘制()getDrawable(R.drawable.drawableid))。

call your drawable at getResources().getDrawable(R.drawable.drawableid));

这篇关于制作自定义选项卡按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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