android中自定义的操作栏选项卡

时间:2014-06-06 02:19:23

标签: android android-actionbar

我正在尝试更改标签背景,指示灯颜色和操作栏标签的文字颜色,但我似乎无法正确使用。

这是我的一些相关代码。

styles.xml

<resources>

    <!--
        Base application theme, dependent on API level. This theme is replaced
        by AppBaseTheme from res/values-vXX/styles.xml on newer devices.

    -->
    <style name="AppBaseTheme" parent="Theme.AppCompat.Light">
        <!--
            Theme customizations available in newer API levels can go in
            res/values-vXX/styles.xml, while customizations related to
            backward-compatibility can go here.

        -->
    </style>

    <!-- Application theme. -->
    <style name="AppTheme" parent="AppBaseTheme">
        <!-- All customizations that are NOT specific to a particular API-level can go here. -->
    </style>

</resources>

MainActivity.java

actionBar = getActionBar();
actionBar.setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.actionBarBG)));
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
actionBar.setDisplayShowTitleEnabled(true);

android.app.ActionBar.Tab tab1 = actionBar.newTab().setText("Unposted")
                .setTabListener(VisitDates.this);

android.app.ActionBar.Tab tab2 = actionBar.newTab().setText("Posted")
                .setTabListener(VisitDates.this);

android.app.ActionBar.Tab tab3 = actionBar.newTab()
                .setText("All visits").setTabListener(VisitDates.this);

actionBar.addTab(tab1);
actionBar.addTab(tab2);
actionBar.addTab(tab3);
actionBar.selectTab(tab1);

1 个答案:

答案 0 :(得分:0)

我发现这个由Jeff Gilfelt here制作的actionBar主题生成器。非常有用的工具。只需设置您想要的设计即可下载文件,将其复制并粘贴到项目的res文件夹中即可完成。

确保在构建或测试应用程序之前首先清理项目。

相关问题