选项卡背景不是以编程方式存在的

时间:2017-03-15 07:23:42

标签: java android android-tabs android-tablayout

如何动态设置标签背景颜色?我曾尝试在java代码中获取 app:tabBackground =" @ drawable / tab_background" 但我无法找到请帮助我的朋友我正在使用设计库通过谷歌我已经尝试了它工作的标签布局中的自定义视图,但差距是在标签之间进行的

After using the custom view

我的代码

 icon_tabs.addTab(icon_tabs.newTab().setCustomView(R.layout.first_tab), true);
            icon_tabs.addTab(icon_tabs.newTab().setCustomView(R.layout.second_tab));
            icon_tabs.addTab(icon_tabs.newTab().setCustomView(R.layout.third_tab));
            icon_tabs.addTab(icon_tabs.newTab().setCustomView(R.layout.fourth_tab));
            icon_tabs.addTab(icon_tabs.newTab().setCustomView(R.layout.five_tab));

自定义标签的布局

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#fff"
    android:orientation="vertical">

    <FrameLayout
        android:id="@+id/first_ll"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/first_tab_drawable">

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="10dp"
            android:src="@drawable/love_home" />
    </FrameLayout>
</FrameLayout>

I need tab layout to be like this

when I select another tab it must be like this

0 个答案:

没有答案