【发布时间】:2013-06-29 19:56:00
【问题描述】:
我正在为 Android 开发一个版本为 17(带有 Galaxy Nexus)的 UI,并且我得到了白色背景。当我在 version15(使用 Galaxy II)中尝试相同的代码时,背景是黑色的。那么,如果代码相同,为什么颜色会不同??
另一个问题是我在 TextView 中使用了 setBackground 函数,它仅适用于 version16 或更高版本。它是 setBackgroundResources 的等价物吗?
这是我正在编写代码的示例。
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);
【问题讨论】:
-
因为你使用的主题
-
在哪里可以查到?我正在尝试删除边框而不是我正在使用的边框并定义 getBackgroundColor ,它的效果会更好一些。如果是主题,我是否可以开发代码以免出现问题并成为最标准的?
标签: android