0

I am trying to change the background color of a layout using a html color reference. But i cant seem to make it work. Here is how i am trying to do it

public class FormEngine {

Context context;
RelativeLayout relLayout;

FormEngine(Context ctx) {
    context = ctx;
    relLayout = new RelativeLayout(context);

}

public void clearScreen(int color) {
    relLayout.setBackgroundColor(color);
}

} and this is how i am calling this class

    FormEngine fEngine = new FormEngine(MainActivity.this);
    setContentView(fEngine.relLayout);
    fEngine.clearScreen(0x708090);

Now if i simply try to use Color.Yellow in setBackground color It works as expected but when i pass a color value like this , it simply shows a white background. Any help would be appreciated.

SubbaReddy PolamReddy
  • 2,083
  • 2
  • 17
  • 23
chossen-addict
  • 370
  • 1
  • 7
  • 31

2 Answers2

1

0x708090 is a fully transparent color. Try this:

fEngine.clearScreen(0xFF708090);
Vladimir Mironov
  • 30,514
  • 3
  • 65
  • 62
1

Android colors use ARGB, so you use 0x00 for the alpha part of the color, which is fully transparent.

Use

fEngine.clearScreen(0xff708090);

instead.

See Hex Colors in Android are some times 8 digits. How? What is the difference between #FFFFFF and #FFFFFF00 for more information.

Community
  • 1
  • 1
Veger
  • 37,240
  • 11
  • 105
  • 116