SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
03/24/15 01:04 AM (9 years ago)

How to set your Android Background Colors

While background color is usually done in your theme settings, there are a few screens (most notably 'Device Information') that have a white background regardless of what your theme is. A little snooping led me to this page: http://code2care.org/pages/set-background-color-android-layout-pragmatically-using-java-and-through-xml/ So, open up the java file for the page in question. I used 'BT_screen_settingsDevice.java' Scroll down until you're into your 'onCreate' method. Find this line: View thisScreensView = inflater.inflate(R.layout.bt_screen_whatever, container, false); and add this code somewhere 'after': thisScreensView.setBackgroundColor(Color.parseColor("#2F4F4F")); this will cause an error, and if you hover the mouse over the error line, you'll see it wants you to import Android Color: import android.graphics.Color; (or you can go ahead and add that line to your import list, so you won't get an error...) What I found most interesting in that page is, although I haven't tried it yet, they mention about allowing 'transparency' with your color. For instance, if your color is a shade of green, like mine: #2F4F4F Adding a value 'just after' the hash (#) mark will allow you to set a transparency level, from opaque (FF) to transparent (00) and any value in between. #FF2F4F4F would be opaque, as the default color is anyway... #AA2F4F4F would have a degree of transparency while retaining the original color. That sounded very interesting, I can't wait to find a use for it. Hope it helps someone somewhere... Cheers! -- Smug
 
Dusko
Veteran developer
Profile
Posts: 998
Reg: Oct 13, 2012
Beograd
22,680
like
03/24/15 03:55 AM (9 years ago)
Very interesting, thank you for sharing!
 
CMCOFFEE
Android Fan
Profile
Posts: 2017
Reg: Jan 04, 2013
Amarillo, Texas
26,670
like
03/24/15 05:03 AM (9 years ago)
Awesome thanks! David has a methis thathe parses colors. I think in Bt_colors.Java.It's a static method. I'm not sure if it uses the same method and can do the transparency though
 
LA
Aspiring developer
Profile
Posts: 3278
Reg: Aug 16, 2012
Jerseyville, IL
42,880
like
03/24/15 05:27 AM (9 years ago)
Yes and you can also change the colors in the XML file. LA
 
Arubaman
Aspiring developer
Profile
Posts: 636
Reg: Oct 20, 2011
Akron
16,910
like
03/24/15 10:03 AM (9 years ago)
Very nice find, thanks.
 
nadthevlad
Code is Art
Profile
Posts: 1025
Reg: Jun 07, 2012
Denver
21,850
like
03/24/15 06:12 PM (9 years ago)
Another buzztouch bookmark.
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.