views:

11

answers:

2

hello,

I am trying to reproduce the behaviour of this simple layout :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:background="#0000ff"/>


a linearlayout with blue background taking all the available space.



I can't understand why this java code doesn't work ? the screen stays black. can somebody advise ?

LinearLayout layout = new LinearLayout(this, null);
layout.setBackgroundColor(0xff);
layout.setOrientation(LinearLayout.VERTICAL);
layout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT));
setContentView(layout);

thanks.

A: 

Try to set color correctly, look at http://stackoverflow.com/questions/3572773/how-to-give-textcolor-to-textview-in-class-file/3572841#3572841 for example.

Konstantin Burov
thank you very much ! layout.setBackgroundColor(android.graphics.Color.BLUE);
sbw
A: 

0xff in code is a transparent blue color :) Use 0xff0000ff.

Romain Guy