완전히 작동하는 사용자 지정 비트 맵 단추가 있지만 이미지 뒤에 배경이 흰색 사각형으로 표시됩니다. 색상이 흰색 인 곳을 찾았지만 완전히 투명하게 만드는 방법을 알 수 없습니다. 어떤 아이디어? 나는 5.0사용자 정의 비트 맵 버튼 필드를 투명 배경으로 사용하려면 어떻게합니까?
참고 버튼 이미지가 모서리에 투명성을 사용하여 파일을 PNG로 둥근 코너 블랙 베리 자바 JDE에서 프로그래밍 해요
코드 :
public class BitmapButtonField extends Field
{
Bitmap _currentPicture;
private Bitmap _onPicture;
Bitmap _offPicture;
private int id;
public BitmapButtonField (Bitmap onImage, Bitmap offImage)
{
super(Field.FOCUSABLE|Field.FIELD_HCENTER);
_offPicture = offImage;
_onPicture = onImage;
_currentPicture = _onPicture;
}
public void setButtonImage (Bitmap onImage, Bitmap offImage)
{
_offPicture = offImage;
_onPicture = onImage;
_currentPicture = _onPicture;
}
public void setButtonId(int id)
{
this.id = id;
}
public int getButtonId()
{
return this.id;
}
public int getPreferredHeight()
{
return _onPicture.getHeight();
}
public int getPreferredWidth()
{
return _onPicture.getWidth();
}
protected void onFocus(int direction)
{
_currentPicture = _offPicture;
invalidate();
}
protected void onUnfocus()
{
_currentPicture = _onPicture;
invalidate();
}
protected void drawFocus(Graphics g, boolean on)
{
g.setBackgroundColor(Color.BLACK);
}
protected void layout(int width, int height)
{
setExtent(Math.min(width, getPreferredWidth()), Math.min(
height, getPreferredHeight()));
}
protected void paintBackground(Graphics g) {
int prevColor = g.getColor();
int prevAlpha = g.getGlobalAlpha();
g.setColor(Color.YELLOW);
g.setGlobalAlpha(0);
g.fillRect(0, 0, getWidth(), getHeight()); // or g.getClippingRect()
g.setColor(prevColor);
g.setGlobalAlpha(prevAlpha);
}
protected void paint (Graphics graph){
graph.setColor(Color.WHITE);
//super.paint(graph);
graph.fillRect(0, 0, getWidth(), getHeight());
graph.drawBitmap(0, 0, getWidth(), getHeight(),
_currentPicture, 0, 0);
}
protected boolean navigationClick(int status, int time)
{
fieldChangeNotify(0);
return true;
}
public boolean keyChar(char key, int status, int time)
{
if (key == Characters.ENTER)
{
fieldChangeNotify(0);
return true;
}
return false;
}
}
당신은'protected void drawFocus (Graphics g, boolean on)'과'protected void paintBackground (Graphics g)'를 구현했다. 또한 초점을 맞춘 상태의 배경 이미지도 지정했습니다. 'paintBackground'와'drawFocus'의 구현을 제거 할 수 있습니다. 또한 그래픽 색상을 흰색으로 설정하고 사각형을 채우는 선은'페인트 '방법에서 삭제할 수 있습니다. 즉, 비트 맵 이미지를'paint' 메소드로 페인트 할 필요가 있습니다. 나는 당신의 코드를 http://pastebin.com/g9n8bqYc에서 수정했다. 당신은 그것을 (나는 그것을 테스트하지 않았다) 확인할 수 있습니다. – Rupak
완벽하게 작동 한 Rupak! 고마워요. 나는 여기에 당신에게 명성을주고 자 노력하지만 그게 나를시키지 않는다. ( –