gpt4 book ai didi

user-interface - BlackBerry - 自定义菜单工具栏

转载 作者:行者123 更新时间:2023-12-03 22:43:44 25 4
gpt4 key购买 nike

我是 BlackBerry 编程的初学者,我需要在我的应用程序中用自定义菜单替换默认菜单(当您按下菜单按钮时),水平。最好的描述是我想要与黑莓 WeatherEye 应用程序相同的结果......

alt text http://www.blackberrybing.com/resource/pics/201002/WeatherEye-OS-45.jpg

我知道如何创建默认菜单,但这个我不知道!
谢谢,

最佳答案

您需要做的是:

  • 创建 SizebleVFManager (contentManager) 作为 VerticalFieldManager 的扩展
  • 将显示宽度和高度 =(显示高度 - 菜单高度)大小设置为 contentManager
  • 将 contentManager 添加到屏幕
  • 创建 Horizo​​ntalFieldManager(菜单管理器)
  • 创建 BitmapButtonField (menuButton) 作为 ButtonField 的扩展
  • 将 FieldChangeListeners 设置为 menuButtons
  • 将 menuButtons 添加到 menuManager
  • 将 menuManager 添加到屏幕

  • SizebleVFManager 示例:
    class SizebleVFManager extends VerticalFieldManager
    {
    int mWidth = 0;
    int mHeight = 0;
    public SizebleVFM(int width, int height, long style) {
    super(style);
    mWidth = width;
    mHeight = height;
    }

    public SizebleVFM(int width, int height) {
    mWidth = width;
    mHeight = height;
    }

    public int getPreferredWidth() {
    return mWidth;
    }

    public int getPreferredHeight() {
    return mHeight;
    }

    protected void sublayout(int width, int height) {
    width = getPreferredWidth();
    height = getPreferredHeight();
    super.sublayout(width, height);
    setExtent(width, height);
    }
    }

    ...
    SizebleVFManager contentManager = 
    new SizebleVFManager(Display.getWidth(), Display.getHeight(),
    VERTICAL_SCROLL|VERTICAL_SCROLLBAR);

    也可以看看
    sample of BitmapButtonField and Toolbar

    PS虽然最好使用标准菜单......

    更新

    如果要禁用默认菜单功能,请取消 MENU 键:
    protected boolean keyDown(int keycode, int time) {
    if(Keypad.KEY_MENU == Keypad.key(keycode))
    {
    return true;
    }
    else
    return super.keyDown(keycode, time);
    }

    更新

    我已经安装了那个美妙的 weather application并了解此示例可能更相似,但有几项改进:
  • 使用 CyclicHFManager 作为 Horizo​​ntalFieldManager 的扩展
  • 在“菜单”按钮上显示/隐藏 menuManager 单击

  • CyclicHFManager 是一个管理器,它将在视觉上将注意力集中在同一个地方,并循环运行所有字段。喜欢在 BlackBerry - Custom centered cyclic HorizontalFieldManager
    class CyclicHFManager extends HorizontalFieldManager {
    int mFocusedFieldIndex = 0;
    boolean mCyclicTurnedOn = false;

    public void focusChangeNotify(int arg0) {
    super.focusChangeNotify(arg0);
    if (mCyclicTurnedOn) {
    int focusedFieldIndexNew = getFieldWithFocusIndex();
    if (focusedFieldIndexNew != mFocusedFieldIndex) {
    if (focusedFieldIndexNew - mFocusedFieldIndex > 0)
    switchField(0, getFieldCount() - 1);
    else
    switchField(getFieldCount() - 1, 0);
    }
    }
    else
    {
    mFocusedFieldIndex = getFieldWithFocusIndex();
    }
    }

    private void switchField(int prevIndex, int newIndex) {
    Field field = getField(prevIndex);
    delete(field);
    insert(field, newIndex);
    }
    }

    alt text http://img109.imageshack.us/img109/6176/toolbarj.jpg

    以及整个代码示例:
    abstract class AScreen extends MainScreen {
    boolean mMenuEnabled = false;
    SizebleVFManager mContentManager = null;
    CyclicHFManager mMenuManager = null;

    public AScreen() {
    mContentManager = new SizebleVFManager(Display.getWidth(), Display
    .getHeight(), VERTICAL_SCROLL | VERTICAL_SCROLLBAR);
    add(mContentManager);

    // mMenuManager = new CyclicHFManager(Display.getWidth(), 60);
    mMenuManager = new CyclicHFManager();
    mMenuManager.setBorder(BorderFactory.createBevelBorder(new XYEdges(4,
    0, 0, 0), new XYEdges(Color.DARKBLUE, 0, 0, 0), new XYEdges(
    Color.WHITE, 0, 0, 0)));
    mMenuManager.setBackground(BackgroundFactory
    .createLinearGradientBackground(Color.DARKBLUE, Color.DARKBLUE,
    Color.LIGHTBLUE, Color.LIGHTBLUE));

    for (int i = 0; i < 10; i++) {
    Bitmap nBitmap = new Bitmap(60, 60);
    Graphics g = new Graphics(nBitmap);
    g.setColor(Color.DARKBLUE);
    g.fillRect(0, 0, 60, 60);
    g.setColor(Color.WHITE);
    g.drawRect(0, 0, 60, 60);
    Font f = g.getFont().derive(Font.BOLD, 40);
    g.setFont(f);
    String text = String.valueOf(i);
    g.drawText(text, (60 - f.getAdvance(text)) >> 1, (60 - f
    .getHeight()) >> 1);

    Bitmap fBitmap = new Bitmap(60, 60);
    g = new Graphics(fBitmap);
    g.setColor(Color.DARKBLUE);
    g.fillRect(0, 0, 60, 60);
    g.setColor(Color.GOLD);
    g.drawRect(0, 0, 60, 60);
    g.setFont(f);
    g.drawText(text, (60 - f.getAdvance(text)) >> 1, (60 - f
    .getHeight()) >> 1);

    BitmapButtonField button = new BitmapButtonField(nBitmap, fBitmap,
    fBitmap);
    button.setCookie(String.valueOf(i));
    button.setPadding(new XYEdges(0, 18, 0, 18));

    button.setChangeListener(new FieldChangeListener() {
    public void fieldChanged(Field field, int context) {
    Dialog.inform("Button # " + (String) field.getCookie());
    }
    });

    mMenuManager.add(button);
    }
    }

    protected boolean keyDown(int keycode, int time) {
    if (Keypad.KEY_MENU == Keypad.key(keycode)) {
    if (mMenuManager.getManager() != null) {
    delete(mMenuManager);
    mMenuManager.mCyclicTurnedOn = false;
    mContentManager.updateSize(Display.getWidth(), Display
    .getHeight());
    } else {
    add(mMenuManager);
    mMenuManager.getField(2).setFocus();
    mMenuManager.mCyclicTurnedOn = true;
    mContentManager.updateSize(Display.getWidth(), Display
    .getHeight()
    - mMenuManager.getHeight());
    }
    return true;
    } else
    return super.keyDown(keycode, time);
    }
    }

    class FirstScreen extends AScreen {

    public FirstScreen() {
    mContentManager.add(new LabelField("This is a first screen"));
    }
    }

    public class ToolbarMenuApp extends UiApplication {

    public ToolbarMenuApp() {
    pushScreen(new FirstScreen());
    }

    public static void main(String[] args) {
    (new ToolbarMenuApp()).enterEventDispatcher();
    }

    }

    关于user-interface - BlackBerry - 自定义菜单工具栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2656169/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com