调用“ tabLayout.setupWithViewPager”后,出现白色背景color_accent

时间:2019-08-23 13:18:06

标签: android

在活动A中调用tabLayout.setupWithViewPager之后,当我调用startActivity(this,BActivity.class)时;背景设置为@ color / white或#ffffff的视图显示为@ color / colorAccent。

这是我的代码:

活动xml:

<layout>
    <data>
        <variable
            name="shop"
            type="com.amir.ir.chapar.model.Shop" />
    </data>

    <androidx.coordinatorlayout.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        tools:context=".ui.activities.ShopActivity">


        <com.google.android.material.appbar.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fitsSystemWindows="true">


            <!--collapsing toolbar layout-->


            <!--toolbar-->

            <com.google.android.material.tabs.TabLayout
                android:id="@+id/tab_layout"
                style="@style/my_tab_layout_style"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                app:layout_scrollFlags="snap"
                app:tabMode="scrollable" />
        </com.google.android.material.appbar.AppBarLayout>


        <!--nested scroll view-->

    </androidx.coordinatorlayout.widget.CoordinatorLayout>
</layout>

活动Java:

public class ShopActivity extends AppCompatActivity {

private ActivityShopBinding mBinding;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_shop);

    mBinding = DataBindingUtil.setContentView(this, R.layout.activity_shop);

    mBinding.viewPager.setAdapter(new ViewPagerAdapter(getSupportFragmentManager(), initFragments(), fakeData()));
    mBinding.tabLayout.setupWithViewPager(mBinding.viewPager);

    mBinding.ivMore.setOnClickListener(v -> {
        startActivity(new Intent(this, CartActivity.class));
    });
}

}

活动B xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"

    android:background="#ffffff" />

活动B Java:

public class TestActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test);
    }
}

我的主题是:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

有人知道什么是大麻吗?

0 个答案:

没有答案