different behaviour creating layout using xml / java
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 t开发者_如何转开发he 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.
Try to set color correctly, look at how to give textcolor to textview in class file for example.
0xff in code is a transparent blue color :) Use 0xff0000ff.
精彩评论