BlackBerry에서 클릭 이벤트 중에 배경색을 변경하는 방법은 무엇입니까? 예를 들어 길게 누르면 배경색을 변경해야합니다. 나를 위해 그것은 기본 색 파란색 걸립니다. 그것을 바꾸는 방법?BlackBerry에서 클릭 이벤트 중에 ButtonField 배경을 변경하려면
이것은 사용자 정의 buttton 필드입니다. 그러나 버튼 클릭 이벤트의 기본 청색을 표시합니다.
public class CustomButtonField extends ButtonField implements GlobalConstant {
int mHeight;
int mWidth;
public final static int DEFAULT_BACKGROUND_COLOR_NORMAL = 0x167c9c;
public final static int DEFAULT_BACKGROUND_COLOR_ON_FOCUS = 0x188118;
private int backgroundColorNormal = DEFAULT_BACKGROUND_COLOR_NORMAL;
private int backgroundColorOnFocus = DEFAULT_BACKGROUND_COLOR_ON_FOCUS;
private Background noraml_bg;
private Background focus_bg;
private boolean isFocusable;
private boolean isround_button = false;
public CustomButtonField(int height, int width, String label) {
super(label, CONSUME_CLICK);
noraml_bg = menuButton_bgNormal;
focus_bg = menuButton_bgFocus;
mHeight = height;
mWidth = width;
this.isFocusable = true;
setBorder(BorderFactory.createSimpleBorder(new XYEdges(0, 0, 0, 0)));
setBorder(VISUAL_STATE_ACTIVE,
BorderFactory.createSimpleBorder(new XYEdges(0, 0, 0, 0)));
}
public CustomButtonField(int height, int width, String label, boolean isround_button) {
super(label, CONSUME_CLICK);
this.isround_button = isround_button;
noraml_bg = roundButton_bgNormal;
focus_bg = roundButton_bgFocus;
mHeight = height;
mWidth = width;
this.isFocusable = true;
XYEdges padding = new XYEdges(1,1,1,1);
XYEdges color = new XYEdges (Color.BLACK,Color.BLACK,Color.BLACK,Color.BLACK);
int lineStyle = Border.STYLE_SOLID;
Border roundedBorder = BorderFactory.createSimpleBorder(padding, color, lineStyle);
setBorder(roundedBorder);
}
/*
* (non-Javadoc)
*
* @see net.rim.device.api.ui.component.ButtonField#getPreferredHeight()
*/
public int getPreferredHeight() {
return mHeight;
}
/*
* (non-Javadoc)
*
* @see net.rim.device.api.ui.component.ButtonField#getPreferredWidth()
*/
public int getPreferredWidth() {
return mWidth;
}
/*
* (non-Javadoc)
*
* @see net.rim.device.api.ui.component.ButtonField#layout(int, int)
*/
protected void layout(int width, int height) {
super.layout(mWidth, mHeight);
setExtent(mWidth, mHeight);
}
/*
* (non-Javadoc)
*
* @see
* net.rim.device.api.ui.component.ButtonField#paint(net.rim.device.api.
* ui.Graphics)
*/
protected void paint(Graphics graphics) {
String label = getLabel();
int x = (getPreferredWidth() - getFont().getAdvance(label)) >> 1;
int y = (getPreferredHeight() - getFont().getHeight()) >> 1;
if (isFocus() == false) {
this.setBackground(noraml_bg);
if(isround_button){
graphics.setColor(0x666666);
}else{
graphics.setColor(Color.WHITE);
}
graphics.drawText(label, x, y);
} else {
this.setBackground(focus_bg);
graphics.setColor(Color.WHITE);
graphics.drawText(label, x, y);
}
}
protected void drawFocus(Graphics graphics, boolean on) {
if (on) {
graphics.setColor(backgroundColorOnFocus);
} else {
graphics.setColor(backgroundColorNormal);
}
}
public boolean isFocusable() {
return isFocusable;
}
은}
안녕하세요 Rupak, 귀하의 대답은 일반 및 포커스 상태에 대한 배경색을 변경하는 것입니다 ....하지만 버튼 클릭 이벤트 중 하나 더 색상을 표시 .... 이전 응답 .... 감사합니다. –
실제로 있음 우리의 응용 프로그램, 사용자 정의 단추 필드에 대해 우리는 0x2e7594 및 0x134f74 그라데이션 색상 코드를 보통으로 설정합니다. 초점을위한 0x8cc10b & 0x4e7500 색상 그라디언트 색상 코드. 버튼 클릭 이벤트의 경우 기본 색상은 세 번째 색상으로 표시됩니다. 따라서 기본 파란색을 포커스 그라디언트 색상 (0x8cc10b 및 0x4e7500)으로 변경해야합니다. 클릭 이벤트의 버튼 기본 파란색을 변경하는 방법 –
위에 게시 된 코드를 사용해 보셨습니까? 이것은 하나의 예이며 Field의 모든 가능한 시각적 상태에 대한 배경을 ButtonField로 설정합니다. 코드를 게시하지 않으면이 문제와 관련하여 도움을 줄 수 없습니다. 그리고 저는 여러분이 'VISUAL_STATE_ACTIVE'에 대해서 이야기하고 있다고 생각합니다. – Rupak