Set opacity to sliding tab layout?

977 views Asked by At

I am using a view pager, fragmentpageradapter, and sliding tab layout in my android app.. I am looking to set opacity to my sliding tab layout so that you can partially see the scrollable content in the background--i would like to have this blurred as well, though I am taking it one step at a time. Right now when I assign opacity to my xml, in my background color, it assigns opacity to my icons rather than the background behind the icons.. how can I fix this??

Here is my xml:

<wxyc.wxyc_consolidate.TabLayoutTools.SlidingTabLayout
    android:id="@+id/sliding_tabs"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:layout_below="@id/wxyc"
    android:layout_gravity="center"
    android:background="#ffcbcbcb"
    android:gravity="center"
    android:layout_alignParentBottom="true"
    />

And here is where I implement the slidingTabs:

    MyFragmentPagerAdapter fragmentPagerAdapter = new MyFragmentPagerAdapter(getSupportFragmentManager(),
            MainActivity.this, liveStreamFragment);

    // getSupportFragmentManager allows use to interact with the fragments
    // MyFragmentPagerAdapter will return a fragment based on an index that is passed
    viewPager.setAdapter(fragmentPagerAdapter);

    // Initialize the Sliding Tab Layout
    SlidingTabLayout slidingTabLayout = (SlidingTabLayout) findViewById(R.id.sliding_tabs);
    slidingTabLayout.setCustomTabView(R.layout.custom_tab, 0);
    slidingTabLayout.setDistributeEvenly(true);
    slidingTabLayout.setBackgroundColor(Color.rgb(202, 202, 212));


    slidingTabLayout.setFillViewport(true);
    slidingTabLayout.setViewPager(viewPager);

    slidingTabLayout.setViewPager(viewPager);
1

There are 1 answers

4
tachyonflux On

The first 2 hexadecimal digits in the background is the opacity. Set them to something less than ff if you want a semi-transparent background.

You also need to have the SlidingTabLayout overlap the ViewPager if you want to see it in the background.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <android.support.v4.view.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/white"/>
    <com.example.android.common.view.SlidingTabLayout
        android:id="@+id/sliding_tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:background="#aacbcbcb"/>
</RelativeLayout>