将不透明度设置为滑动选项卡布局



我在android应用程序中使用了视图寻呼机、fragmentpageradapter和滑动选项卡布局。。我希望将不透明度设置为我的滑动选项卡布局,这样你就可以部分地看到背景中的可滚动内容——我也希望这个模糊,尽管我一步一个脚印。现在,当我以背景色为xml指定不透明度时,它会为图标而不是图标后面的背景指定不透明度。。我该怎么解决这个问题??

这是我的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"
    />

这里是我实现滑动标签的地方:

    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);

背景中的前两个十六进制数字是不透明度。如果想要半透明背景,请将它们设置为小于ff的值。

如果您想在后台看到SlidingTabLayout,还需要使其与ViewPager重叠。

<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>

最新更新