Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change Android ViewPager Background Color?

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.

like image 924
user310291 Avatar asked Apr 28 '14 13:04

user310291


3 Answers

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);
like image 126
Spring Breaker Avatar answered Sep 17 '22 15:09

Spring Breaker


Try this

private ViewPager mPager;
mPager = (ViewPager) view.findViewById(R.id.pager);
mPager.setBackgroundColor(Color.BLACK);
like image 23
Nikhil Avatar answered Sep 17 '22 15:09

Nikhil


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.

like image 22
BladeCoder Avatar answered Sep 20 '22 15:09

BladeCoder