Several classes in android manifest.
-
wrote on 20 May 2016, 03:18 last edited by
Hello!
I wanted to hide ActionBar in android.// java code if(getSupportActionBar().isShowing()) { View decorView = getWindow().getDecorView(); int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN; decorView.setSystemUiVisibility(uiOptions); getSupportActionBar().hide(); } else { getSupportActionBar().show(); }
To test this code, I created an empty project "Blanck Activity" in Android Studio. I added code to the button. Works great.
Now the implementation in Qt.// main.cpp QAndroidJniObject::callStaticMethod<void>("AndroidBar", "hideNavigationBar");
// AndroidBar.java import android.view.View; import android.util.Log; public class AndroidBar extends org.qtproject.qt5.android.bindings.QtActivity { private static final String TAG = AndroidBar.class.getSimpleName(); public static void hideNavigationBar() { Log.d(TAG, "Hide navigation bar"); View decorView = getWindow().getDecorView(); int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN; decorView.setSystemUiVisibility(uiOptions); } }
But there is an error:
non-static method getWindow() cannot be referenced from a static contextThen I decided to create a separate class.
// AndroidBar.java import android.util.Log; public class AndroidBar extends org.qtproject.qt5.android.bindings.QtActivity { private static final String TAG = AndroidBar.class.getSimpleName(); public static void hideNavigationBar() { Log.d(TAG, "Hide navigation bar"); MyTest test = new MyTest(); test.hideBar(); test = null; } }
// MyTest.java import android.view.View; import android.util.Log; public class MyTest extends org.qtproject.qt5.android.bindings.QtActivity { private String TAG = AndroidBar.class.getSimpleName(); public void hideBar() { Log.d(TAG, "Hide bar"); View decorView = getWindow().getDecorView(); int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN; decorView.setSystemUiVisibility(uiOptions); } }
No errors, but the method is not called. In the Android Studio it works.
// .pro android { QT += androidextras ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android OTHER_FILES += android/AndroidManifest.xml \ android/src/AndroidBar.java \ android/src/MyTest.java }
// AndroidManifest.xml <application android:icon="@drawable/icon" android:label="@string/app_name" android:hardwareAccelerated="true" android:name="org.qtproject.qt5.android.bindings.QtApplication"> <activity android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|locale|fontScale|keyboard|keyboardHidden|navigation" android:label="@string/app_name" android:name="org.qtproject.qt5.android.bindings.QtActivity" android:screenOrientation="landscape">
How to add this class to the project? Or are there other solutions?
-
Hello!
I wanted to hide ActionBar in android.// java code if(getSupportActionBar().isShowing()) { View decorView = getWindow().getDecorView(); int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN; decorView.setSystemUiVisibility(uiOptions); getSupportActionBar().hide(); } else { getSupportActionBar().show(); }
To test this code, I created an empty project "Blanck Activity" in Android Studio. I added code to the button. Works great.
Now the implementation in Qt.// main.cpp QAndroidJniObject::callStaticMethod<void>("AndroidBar", "hideNavigationBar");
// AndroidBar.java import android.view.View; import android.util.Log; public class AndroidBar extends org.qtproject.qt5.android.bindings.QtActivity { private static final String TAG = AndroidBar.class.getSimpleName(); public static void hideNavigationBar() { Log.d(TAG, "Hide navigation bar"); View decorView = getWindow().getDecorView(); int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN; decorView.setSystemUiVisibility(uiOptions); } }
But there is an error:
non-static method getWindow() cannot be referenced from a static contextThen I decided to create a separate class.
// AndroidBar.java import android.util.Log; public class AndroidBar extends org.qtproject.qt5.android.bindings.QtActivity { private static final String TAG = AndroidBar.class.getSimpleName(); public static void hideNavigationBar() { Log.d(TAG, "Hide navigation bar"); MyTest test = new MyTest(); test.hideBar(); test = null; } }
// MyTest.java import android.view.View; import android.util.Log; public class MyTest extends org.qtproject.qt5.android.bindings.QtActivity { private String TAG = AndroidBar.class.getSimpleName(); public void hideBar() { Log.d(TAG, "Hide bar"); View decorView = getWindow().getDecorView(); int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN; decorView.setSystemUiVisibility(uiOptions); } }
No errors, but the method is not called. In the Android Studio it works.
// .pro android { QT += androidextras ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android OTHER_FILES += android/AndroidManifest.xml \ android/src/AndroidBar.java \ android/src/MyTest.java }
// AndroidManifest.xml <application android:icon="@drawable/icon" android:label="@string/app_name" android:hardwareAccelerated="true" android:name="org.qtproject.qt5.android.bindings.QtApplication"> <activity android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|locale|fontScale|keyboard|keyboardHidden|navigation" android:label="@string/app_name" android:name="org.qtproject.qt5.android.bindings.QtActivity" android:screenOrientation="landscape">
How to add this class to the project? Or are there other solutions?
wrote on 9 Jun 2016, 05:00 last edited byCreate a new activity in your andrdoid/src folder subclassing QtActivity.
In this article, all explained in detail - https://www.kdab.com/qt-android-episode-7/.
At the end of the article there is the source code.Add method in the class MyActivity.
@Override public void onWindowFocusChanged(boolean hasFocus) { Log.d("BLABLA", "Window focus changed"); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { if (hasFocus) { Log.d("SCREEN","IMMERSIVE MODE ACTIVE"); getWindow().getDecorView().setSystemUiVisibility( View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);} } if (!QtApplication.invokeDelegate(hasFocus).invoked) super.onWindowFocusChanged(hasFocus); }
Do not forget about it:
import android.os.Build; import android.view.View; import android.util.Log;
It works on version 4.4.