想知道有沒有人遇到過這個問題。我有一個應用程序,它可以檢測臉部,並在臉部周圍放置可觸摸的方塊,全部放在RelativeLayout中。當我感動時,我想添加一些文本到視圖中,這很好用,但是當我去簡單地向TextView添加背景時,它什麼也不做。我試過了一個標準背景setBackgroundColor(Color.WHITE);
,而不是我真正想要使用的背景(setBackgroundResource(R.drawable.nametag);
),而且什麼也沒有。Android TextView無法設置背景顏色或可繪製
TextView nameLabelView = new TextView(activity);
nameLabelView.setText(fullname);
nameLabelView.setTextColor(Color.BLACK);
nameLabelView.setBackgroundColor(Color.WHITE); //TODO <-- wth??
//nameLabelView.setBackgroundResource(R.drawable.nametag);
nameLabelView.setGravity(Gravity.CENTER_HORIZONTAL);
//duplicate layout params from active face View so label sits inside it
ViewGroup.LayoutParams lp = selectedFaceView.getLayoutParams();
nameLabelView.setLayoutParams(lp);
facePreviewLayout.addView(nameLabelView);
奇怪的是,希望這是顯而易見的人在那裏,在此先感謝!
還有很多改進的空間:) – janzoner