Question

ViewPager Background is grey. I can't find on internet any clear article that shows how to just change that background color in black for example.Any idea will be appreciated.

Was it helpful?

Solution

You can achieve it in 2 ways,

1.Add the following in your ViewPager in the xml

android:background="#000000"

2.Do it dynamically like below,

ViewPager pager= (ViewPager)findViewById(R.id.pager);
pager.setBackgroundColor(Color.BLACK);

OTHER TIPS

Try this

private ViewPager mPager;
mPager = (ViewPager) view.findViewById(R.id.pager);
mPager.setBackgroundColor(Color.BLACK);

A ViewPager is not grey by default, it's transparent like other ViewGroups, so you will see your parent layout background or window background by default.

If you want to change the background color of your whole Activity, I suggest that you override the android:windowBackground attribute in your Activity's theme, which is more efficient.

You can set android:background="@android:color/transparent" to ViewPager in your xml file

and set android:background="@android:color/black" for parent layout.

I hope this will help.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top