开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜