2012-03-12 5 views
0

현재 내 응용 프로그램에는 4 개의 비트 맵 단추가 ​​있습니다. 특정 버튼에 집중할 때마다 이름이 화면의 어딘가에 나타날 수 있도록 각 버튼의 레이블/이름과 같은 것을 갖고 싶습니다. 상단에 있거나 버튼 아래에있을 수 있습니다.비트 맵 단추 필드의 레이블/이름

어떻게하면됩니까? 비트 맵 버튼 필드 레이블링을 검색했지만 실제로 도움이되는 것을 찾지 못했습니다.

답변

3

버튼 필드 아래에 CustomLabelField를 넣을 수 있습니다. ButtonFields onFocus(int direction)onUnfocus() 메서드를 재정의하십시오. 그들이 당신 CustomLabelField (댓글 후)

class CustomLabelField extends Field { 
    String label; 
    public void setLabel(String label){ 
     this.label = label; 
     invalidate(); 
    } 
    protected void layout(int arg0, int arg1) { 
     setExtent(Display.getWidth, getFont().getHeight()); 
    } 

    protected void paint(Graphics graphics) { 
     graphics.setColor(Color.Black); 
     graphics.drawText(label, 0, 0); 
    } 
} 

편집

setLabel(String label) 메소드를 호출 내부에서이 사용자 정의 버튼을 사용하고 귀하의 추가 기능을 추가 할 수 있습니다. 이것이 작동한다면 시도하지 않았지만 작동해야합니다.

import net.rim.device.api.ui.component.BitmapField; 
import net.rim.device.api.ui.container.MainScreen; 

public class CustomButtonField extends BitmapField{ 
    private String label = ""; 
    private MainScreen yourScreen; 

    public CustomButtonField(String label, MainScreen yourScreen) { 
     super(); 
     this.label = label; 
     this.yourScreen = yourScreen; 
    } 

    protected void onFocus(int direction) { 
     yourScreen.setTitle(label); 
     super.onFocus(direction); 
    } 

    protected void onUnfocus() { 
     yourScreen.setTitle(""); 
     super.onUnfocus(); 
    } 
} 
+0

레이블을 응용 프로그램 제목 표시 줄에 덮어 쓰려면? 그러나 그것은 좋은 도움, 대단히 감사합니다 ~ – ocinisme

+0

예, 가능합니다. –

+0

어떻게 설명 할까? – ocinisme