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.

有帮助吗?

解决方案

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

其他提示

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top