How to change background color of Android ViewPager?

ViewPagerThe background is gray. I cannot find any clear article on the Internet that shows how easy it is to change this background color to black, for example. Any idea would be appreciated.

+4
source share
4 answers

You can achieve this in two ways,

1. Add the following to ViewPagerin xml

android:background="#000000"

2. Give dynamically, as shown below,

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

try it

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

A ViewPager , , ViewGroup s, .

, android:windowBackground , .

+3
source

You can install android:background="@android:color/transparent"in ViewPagerto your XML file

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

Hope this helps.

0
source

Source: https://habr.com/ru/post/1538408/


All Articles