背景颜色与旧的Android版本一起回来了

时间:2013-06-19 15:03:02

标签: android

我正在使用适用于Android的版本17(使用Galaxy Nexus)开发UI,并且我将背景设置为白色。当我在版本15(使用Galaxy II)中尝试相同的代码时,背景是黑色的。那么,如果代码相同,为什么颜色会不同?

另一个问题是我正在使用TextView函数setBackground,它只适用于版本16或更新版本。它是setBackgroundResourse的等价物吗?

这是我正在制作代码的一个例子。

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

1 个答案:

答案 0 :(得分:0)

您可以在Manifest文件和style.xml中查看应用程序使用的主题。请参阅this以保持兼容性。