0

I'm developing a UI with the version17 (With Galaxy Nexus) for Android, and, I got the background white. When I try the same code in a version15 (with Galaxy II) the background is black. So, Why is the color different if the code is the same??

Another question is that I was using to TextView the function setBackground and it's just for the version16 or newer. Is it the setBackgroundResourse the equivalent?

This is an example of as I'm making the code.

FrameLayout frame = new FrameLayout(this);
        frame.setId(findId());
        FrameLayout.LayoutParams frameParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,FrameLayout.LayoutParams.MATCH_PARENT);               
        frame.setBackgroundResource(idBorder);
        frame.setLayoutParams(frameParams);


        //Relative layaout que engloba todo
        RelativeLayout relativeLayout = new RelativeLayout(this);
        //relativeLayout.setId(findId());
        RelativeLayout.LayoutParams relativeParams = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);     
        relativeLayout.setLayoutParams(relativeParams);         
        relativeLayout.setPadding(5, 5, 5, 5);
        relativeParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
        relativeParams.addRule(RelativeLayout.CENTER_VERTICAL);
        relativeLayout.setBackgroundColor(Color.WHITE);
        //relativeLayout.setBackground(getResources().getDrawable(idBorder));
        relativeLayout.setBackgroundResource(idBorder);
        frame.addView(relativeLayout);

        //Nombre de la sala
        TextView textRoomName = new TextView(this);
        textRoomName.setId(findId());
        relativeLayout.addView(textRoomName);

        textRoomName.setText(room.getName());
        RelativeLayout.LayoutParams relativeParamRoomName = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);      
        relativeParamRoomName.addRule(RelativeLayout.ALIGN_PARENT_LEFT);    
        relativeParamRoomName.setMargins(10, 10, 10, 5);    
        textRoomName.setLayoutParams(relativeParamRoomName);
        textRoomName.setTextColor(Color.parseColor("#040404"));
        textRoomName.setTextSize(20);
        textRoomName.setTypeface(null, Typeface.BOLD);
        textRoomName.setPadding(3, 3, 3, 3);        
        //textRoomName.setBackground(getResources().getDrawable(idBorder));
        textRoomName.setBackgroundResource(idBorder);

enter image description here enter image description here

Mat
  • 202,337
  • 40
  • 393
  • 406
Guille
  • 2,248
  • 3
  • 24
  • 42
  • Its because of the theme you are using – Anirudha Agashe Jun 19 '13 at 15:33
  • where could I check it? I'm trying to delete the border than I'm using and define getBackgroundColor and it works a little better. And If it's the theme, could I develop the code so not to have problems and be the most standar possible? – Guille Jun 19 '13 at 15:42

1 Answers1

0

You can see what theme the application is using in Manifest file and style.xml. See this to maintain compatibility.

Community
  • 1
  • 1
Anirudha Agashe
  • 3,510
  • 2
  • 32
  • 47
  • Are you sure? I'm checking it.. Well, I have the version 15 and 17, what it shouldn't be too much difference. I'm using Theme.Light and Holo. It's pretty weird that that is changing the background color of a RelativeLayaout or TextViews – Guille Jun 19 '13 at 16:08
  • I have changed the min and sdkversion to 15 and it continues happening, I guess that if it would be because the theme it should work now. – Guille Jun 19 '13 at 21:26