我想要查看资源png of a house。它基本上只是一个黑暗的主页按钮。
我将其包含在内并作为图片资源导入为可绘制的。
我正在尝试将其设置为按钮,但会以编程方式将其更改为白色。
以下是我试图将颜色更改为白色的方法:
ImageButton txtbtnAccept = new ImageButton(this);
this._surveyHomeButton = txtbtnAccept;
txtbtnAccept.setId(this.generateViewId());
txtbtnAccept.setLayoutParams(new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
layoutParams = (RelativeLayout.LayoutParams) txtbtnAccept.getLayoutParams();
layoutParams.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE);
layoutParams.height = 200;
layoutParams.width = 200;
txtbtnAccept.setScaleType(ImageView.ScaleType.FIT_CENTER);
txtbtnAccept.setAdjustViewBounds(true);
txtbtnAccept.setLayoutParams(layoutParams);
txtbtnAccept.setBackgroundResource(0);
txtbtnAccept.setVisibility(View.GONE);
Bitmap homeImage = BitmapFactory.decodeResource(getResources(), R.drawable.ic_action_home);
Drawable whiteImg = new BitmapDrawable(getResources(), homeImage);
whiteImg.setColorFilter(Color.WHITE, PorterDuff.Mode.MULTIPLY);
txtbtnAccept.setImageDrawable(whiteImg);
txtbtnAccept.setImageBitmap(homeImage);
知道我哪里出错了吗?