我有一個Button
對象和一個Imagebutton
對象。我想要做的就是爲它們分配相同的背景顏色。將相同的背景顏色設置爲按鈕和圖像按鈕?
但圖像按鈕的背景顏色似乎總是比「普通」按鈕的顏色更亮?在S3 Mini上,模擬器上的亮度更亮,亮度更亮。 爲什麼?
private final int BUTTON_BACKGROUND_COLOR_CODE = Color.LTGRAY;
...
RelativeLayout TopLayout = (RelativeLayout) findViewById(R.id.topLayout);
TopLayout.removeAllViews();
TopLayout.setPadding(m_TableRowLeftPadding_px, 8, m_TableRowRightPadding_px, 4);
RelativeLayout.LayoutParams bParams = new RelativeLayout.LayoutParams(m_DefaultButtonWidth_px,
m_CurrentButtonHeight_px);
bParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
bParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
Button itemAddButton = new Button(this);
itemAddButton.getBackground().setColorFilter(BUTTON_BACKGROUND_COLOR_CODE,
PorterDuff.Mode.SRC_IN);
itemAddButton.setLayoutParams(bParams);
itemAddButton.setText(m_Resources.getString(R.string.AddItemButtonString));
itemAddButton.setId(ADD_ITEM_BUTTON_ID);
itemAddButton.setOnClickListener(new View.OnClickListener()
{
...
});
TopLayout.addView(itemAddButton);
RelativeLayout.LayoutParams ibParams = new RelativeLayout.LayoutParams(MIN_IMG_BUTTON_WIDTH,
m_CurrentButtonHeight_px);
ibParams.addRule(RelativeLayout.LEFT_OF, itemAddButton.getId());
ImageButton speechButton = new ImageButton(this);
speechButton.setLayoutParams(ibParams);
// speechButton.setImageDrawable(m_Resources.getDrawable(R.drawable.micro2));
speechButton.setContentDescription(m_Resources.getString(R.string.AddSpeechItemString));
speechButton.getBackground().setColorFilter(BUTTON_BACKGROUND_COLOR_CODE,
PorterDuff.Mode.SRC_IN);
speechButton.setOnClickListener(new View.OnClickListener()
{
...
});
TopLayout.addView(speechButton);
爲什麼不使用兩個'Buttons'或兩個'ImageButtons'而不是一個'Button'和'ImageButton' ?? – Renjith
「爲什麼我的S3 Mini在模擬器上亮了一點,路明亮了?」這取決於設備的屏幕規格。您會在另一款智能手機上看到另一種顏色的亮度。 – JJ86
@RKN:ImageButton不允許設置文本,字體等。而「普通」按鈕不允許添加圖像,這是我的意圖。我只是評論一下,以避免我的圖像的「透明」背景造成的視覺干擾。 –