How to fix alignment for vertical and portrait screen in BlackBerry?

后端 未结 2 621
难免孤独
难免孤独 2021-01-06 22:04

I want to do application which will not change UI even if screen is changed to portrait or landscape direction. How to do that?

2条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-06 22:29

    I have made a static method in one of my library classes:

    public static void disableOrientationChange()
    {
        // force app to use only portrait mode
        int directions = Display.DIRECTION_NORTH;
        UiEngineInstance engineInstance = Ui.getUiEngineInstance();
        if (engineInstance != null)
        {
            engineInstance.setAcceptableDirections(directions);
        }
    }
    

    The trick is that this code only works for screens created after running it. So you must run the code BEFORE you show your first screen.

    I call this method from my Application.main(String args) method, just before the call to enterEventDispatcher().

    public static void main(String[] args)
    {
        MyApp app = new MyApp();
    
        /*
         * BlackBerry OS 5.0.0
         * Disable screen orientation changes
         */
        ScreenUtils.disableOrientationChange();
    
        // enters the event processing loop thread if required
        if (!app.isHandlingEvents())
        {
            app.enterEventDispatcher();
        }
    }
    

提交回复
热议问题