简体   繁体   English

旧的android版本恢复了背景色

[英]The background color is back with old android versions

I'm developing a UI with the version17 (With Galaxy Nexus) for Android, and, I got the background white. 我正在使用适用于Android的version17(带有Galaxy Nexus)开发UI,并且背景变成白色。 When I try the same code in a version15 (with Galaxy II) the background is black. 当我在版本15(使用Galaxy II)中尝试相同的代码时,背景为黑色。 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. 另一个问题是我正在使用TextView函数setBackground,它仅用于version16或更高版本。 Is it the setBackgroundResourse the equivalent? setBackgroundResourse是否等效?

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);

在此处输入图片说明在此处输入图片说明

You can see what theme the application is using in Manifest file and style.xml. 您可以在清单文件和style.xml中查看应用程序正在使用的主题。 See this to maintain compatibility. 请参阅此内容以保持兼容性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM