I want to change fullscreen mode in settings and see the changes after backing from settings to main activity.
I tried:
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
But I can't use it after setting content view of main activity. I tried also:
WindowManager.LayoutParams attrs = mActivity.getWindow().getAttributes();
attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
mActivity.getWindow().setAttributes(attrs);
but i can't use it in onResume() because my app is unable to resume activity throwing null pointer exception at the first open.
Do you have any idea how to do fullscreen setting with changes being seen after resuming to main activity?
Api level 11+
getActionBar.hide();
below Api level 11
you can use getSupportActionBar.hide(); and add v7 support lib to your project
If you are using recent Android (4.4) you can try by adding this to onResume()
View decorView = getWindow().getDecorView();
decorView.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);
In your AndroidManifest.xml
<activity
android:name=".YourSettingsActivity"
android:label=""
android:theme="#android:style/Theme.Holo.NoActionBar.FullScreen"
android:screenOrientation="portrait" >
</activity>
Try this
WindowManager.LayoutParams attrs = getWindow().getAttributes();
attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
getWindow().setAttributes(attrs);
Related
I am trying to set my activity to full screen using this code below:
private void hideSystemUI() {
View decorView = getWindow().getDecorView();
decorView.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
| 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);
}
But I am getting a black color navigation bar on certain phones because of the condition on settings -> display where certain phones need to permit apps to use a fullscreen mode. To address this issue I decided that I need to implement a permission checker when the activity inflates. If there is another way please tell me and I will try to implement it.
Edit:
Here is the link of the conditions for phones that I am talking about:
https://www.gottabemobile.com/how-to-enable-full-screen-apps-on-galaxy-s10/
this problem happen with me for 2 different devices and this because of the front camera notch or screen cutout.
I used this code in oncreate() :
hideSystemUI();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
getWindow().getAttributes().layoutInDisplayCutoutMode =
WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES; }
Or in the theme style xml file add this line :
<item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
In your manifest file put
android:theme="#style/Theme.Design.NoActionBar"
or
android:theme="#style/AppTheme"
and in your activity call hideSystemUI(); before setting the content view
like this :
final int flags = 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;
getWindow().getDecorView().setSystemUiVisibility(flags);
setContentView(R.layout.activity_main);
I need to enter android immersive mode in my react-native app, but when I try View.SYSTEM_UI_FLAG_IMMERSIVE) I got a lot of errors during compilation. I don't know anything about native android development and do it blindfold. So can you please briefly explain what and where I need to past to make it work.
I need only to automatically hide android navigation buttons on app start so it's enough to add few lines of code in MainActivity.java:
#Override
protected void onStart()
{
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);
super.onStart();
}
what about adding android:theme="#android:style/Theme.NoTitleBar.Fullscreen" in your android manifest xml file??
I have the following code:
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);
This code worked fine for Android Lollipop, hiding the navigation bar in sticky immersive mode. But now, when I test it on my phone with Android 6.0, the navigation bar goes away while a black rectangle where the navigation bar used to be remains, blocking a portion of the screen.
Looking back on my question, I'd like to add the solution I'm using now which hasn't failed me since, I don't remember if I saw it somewhere else or came to it myself but I'm glad it works.
public static void activiateFullscreen(Activity activity){
View decorView = activity.getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
if (Build.VERSION.SDK_INT >= 17) {
uiOptions ^= View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_FULLSCREEN
|View.SYSTEM_UI_FLAG_LOW_PROFILE;
}
if (Build.VERSION.SDK_INT >= 19) {
uiOptions ^= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
}
decorView.setSystemUiVisibility(uiOptions);
}
Hope this helps someone!
I've discovered a workaround that seems to resolve this issue. I support portrait and landscape, and noticed that the black rectangle went away if I rotated into landscape or started the app in landscape. Adding the following code to my main activity's onCreate() method (after setting the immersive flags) resolved the issue:
if (Build.VERSION.SDK_INT >= 23) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR);
}
I knew this question is being asked previously but not getting the accurate solution.
I want to hide ActionBar and NavigationBar from my activity in or order to make it full screen. I tried the below code in my Activities OnCreate Method but its showing Action Bar for some fraction of seconds and than making it full screen. In Galaxy S3 (android 4.3), its even more than a second. so how can I make it completely invisible and my activity as full screen completely from the beginning only.
I saw many apps running on S3 only, but their is no ActionBar, not even for fraction seconds.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
if (Build.VERSION.SDK_INT < 19) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
} else {
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);
}
}
In the onCreate function of your activity add this code before setContentView:
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
In AndroidManifest file write
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
If the minimum SDK Version of your application is 19 (KitKat), then you have to add an additional piece of code to your onResume function:
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 );
In AndroidManifest file write
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
in activity tag
and use
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
befor setContentView(R.layout.activity_main);
Try android:theme="#android:style/Theme.NoTitleBar.Fullscreen" in the declaration of your Activtiy in your Manifest.
try this before setContentView
//Remove title bar
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
//Remove notification bar
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
This Android Developer and This Post demonstrates Immersive Full-Screen Mode which allows your app to go full screen.
tltr;
try this snippet which I got from the Android Developer website:
View decorView = getWindow().getDecorView();
// Hide both the navigation bar and the status bar.
// SYSTEM_UI_FLAG_FULLSCREEN is only available on Android 4.1 and higher, but as
// a general rule, you should design your app to hide the status bar whenever you
// hide the navigation bar.
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
Hopefully I helped!
i think you have to write just
getActionBar().hide(); (Above Api level 11)
or
getSupportActionBar().hide();(Up to Api level 8)
thats it...
i have two questions:
one how can i run my application in full screen
how video players run videos in full screen.
i have tried alot and still struggling to achieve this but couldn't find a solution.
the list of solution i found but they are not fulfilling my requirements
this hides only the notification bar.
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
also hides only the notification bar
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen">
it low profiles the navigation bar not hiding it.
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
no effect on my activity.
anyView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
note that:
i am not talking about rooting a device,so please provide those solutions which can work without rooting a device.
i am not talking about hiding only notification bar,but full screen by hiding both navigation bar and notification bar too.
i am talking about jelly beans api 4.1 or greater than 4.1 version of android
and please give answers with code.
after my research and your answers, i am getting this:
but my app should look like this without navigation bar:
i do not want the system navigation bar visible in my app.
I'm not sure what you're after, but the following hides the Notification bar, and the Soft Navigation keys (as seen on Google Nexus-devices), so the app essentially is "full screen".
Edit2
In Android 4.4 (API 19) Google introduced the new Immersive mode which can hide the status & navbar and allow for a truly fullscreen UI.
// This snippet hides the system bars.
private void hideSystemUI() {
// Set the IMMERSIVE flag.
// Set the content to appear under the system bars so that the content
// doesn't resize when the system bars hide and show.
mDecorView.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 // hide nav bar
| View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
| View.SYSTEM_UI_FLAG_IMMERSIVE);
}
// This snippet shows the system bars. It does this by removing all the flags
// except for the ones that make the content appear under the system bars.
private void showSystemUI() {
mDecorView.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
}
Reference:
https://developer.android.com/training/system-ui/immersive.html
Edit:
Tested on Android 4.3 (API 18) and Android 4.1 (API 16) with Soft Nav keys.
#Override
protected void onCreate(Bundle b) {
super.onCreate(b);
setContentView(R.layout.main);
int mUIFlag = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LOW_PROFILE
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
getWindow().getDecorView().setSystemUiVisibility(mUIFlag);
}
For more information read up on http://developer.android.com/reference/android/view/View.html#setSystemUiVisibility(int)
-To hide Status bar:
A great solution I found for that issue, setting each Activity theme & windowSoftInputMode to the following values :
<activity android:name=".MyActivity"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
android:windowSoftInputMode="adjustResize"> <!-- theme : to set the activity to a full screen mode without a status bar(like in some games) -->
</activity> <!-- windowSoftInputMode : to resize the activity so that it fits the condition of displaying a softkeyboard -->
for more info refer here.
-To hide Notification bar:
There are Two ways :
1- root your device, then open the device in adb window command, and then run the following:
adb shell >
su >
pm disable com.android.systemui >
and to get it back just do the same but change disable to enable.
2- add the following line to the end of your device's build.prop file :
qemu.hw.mainkeys = 1
then to get it back just remove it.
and if you don't know how to edit build.prop file:
download EsExplorer on your device and search for build.prop then change it's permissions to read and write, finally add the line.
download a specialized build.prop editor app like build.propEditor.
or refer to that link.
On the new android 4.4 you should add this line:
View.SYSTEM_UI_FLAG_IMMERSIVE;
So the new working solution atleast on nexus4 4.4.2 is
final int mUIFlag =
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LOW_PROFILE
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_IMMERSIVE;
Immersive alone won't work though it works when combined with other flags. see documentation for more details.
Then you add in the activity the activating of this setup as shown here before (I am just adding for consistency)
getWindow().getDecorView().setSystemUiVisibility(mUIFlag);
I made 2 layouts one for regular size and one for full screen and inside full scrreen I get the devices size and and assign it to video player
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getRealSize(size);
int w=size.x;
int h=size.y;
videoPlayer.setFixedSize(w, h);
I think you cant hide the system bar in android 4.0 > (only in tablets, in phones you should be able to)
What you can do is to hide the icons and to disable some buttons(everyone except home)
You can try this:
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
}
Also for disabling the buttons:
This is for back button:
public boolean onKeyDown(int keyCode, KeyEvent event) {
return false;
}
This for the menu:
#Override
public void onWindowFocusChanged(boolean hasFocus) {
try
{
if(!hasFocus)
{
Object service = getSystemService("statusbar");
Class<?> statusbarManager = Class.forName("android.app.StatusBarManager");
Method collapse = statusbarManager.getMethod("collapse");
collapse .setAccessible(true);
collapse .invoke(service);
}
}
catch(Exception ex)
{
}
}
Video Players run in full screen by setting the
myView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
setFlags() before setContentView(View)
This will show the system bar on any user interaction, just like video players do.
The closest you can get to running your app full screen is by setting in Lights Out mode, the system buttons will appear as dots.
To use the lights out mode just use any view in your activity and call
anyView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
For Hiding the navigation bar use this in your onStart() so that every time you get to that activity it will be in full screen mode.
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
I hope this helps !
Android Version: 4.2.2 - Device: Vega Tablet
Android App to Hide Status and System Bar and displaying complete screen I followed these steps.
AndroidManifest.xml
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name">
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
MainActivity.java
super.onCreate(savedInstanceState);
getWindow().getDecorView().setSystemUiVisibility(0x10);
setContentView(R.layout.activity_main);
Above code perfectly worked for my app.
go to your manifest and add this to your activity
<activity
android:name="yourPackage.yourActivity"
android:theme="#android:style/Theme.Black.NoTitleBar">