我正在開發與版本17(與Galaxy Nexus)爲Android的用戶界面,並且,我得到了背景白色。當我在版本15(與Galaxy II)中嘗試相同的代碼時,背景是黑色的。那麼,如果代碼相同,爲什麼顏色不同呢?背景顏色回舊Android版本
另一個問題是,我正在使用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);
它是因爲您使用的主題 –
我可以在哪裏檢查它?我試圖刪除邊框比我使用和定義getBackgroundColor,它的工作更好一點。如果這是主題,我可以開發代碼,以免出現問題併成爲最可能的標準嗎? – Guille