[QT 5.3 for Android] How to change app orientation dynamically?
-
I know the app orientation could be setting in the androidmanifest.xml.
But how to set app orientation dynamically by using QT code?
PS: NOT qml app
PS: I could do the same thing by using setRequestedOrientation() in Android Java code -
I think you should follow the "issue":https://bugreports.qt-project.org/browse/QTBUG-38576 and add the feature request for non QML applications.
-
here is something for you,
package com.exercise.AndroidOrientation;import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;public class AndroidOrientationActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);Button buttonSetPortrait = (Button)findViewById(R.id.setPortrait); Button buttonSetLandscape = (Button)findViewById(R.id.setLandscape); buttonSetPortrait.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}});buttonSetLandscape.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}});
}
}