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">
Related
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 an Android Application that is made using Fragments
I am hiding the bars at top and bottom of my screen, using the following code.
#Override
protected void onResume() {
super.onResume();
isInBackground = false;
if(null == getFragmentManager().findFragmentById(R.id.content_container))
{
getFragmentManager().beginTransaction().add(R.id.content_container,new PresenterFragment(), PresenterFragment.FRAG_TAG).commit();
}
if(Build.VERSION.SDK_INT >=19)
{
View decorView = getWindow().getDecorView();
int uiOptions = 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_STICKY;
decorView.setSystemUiVisibility(uiOptions);
decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {
#Override
public void onSystemUiVisibilityChange(int visibility) {
View decorView = getWindow().getDecorView();
int uiOptions = 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_STICKY;
decorView.setSystemUiVisibility(uiOptions);
}
});
}
}
When the soft keyboard it shown the bars show, I can live with this as they hide when the keyboard is dismissed.However if a dialog Fragment is show while the soft keyboard is shown then when both the keyboard and the dialog fragment are dismissed they bars remain over the top of the application.
My 3 questions are
Is it possible to stop the softkeyboard for changing the UI mode?
Is it possible to stop the showing of DialogsFraments from changing the UI mode?
edit: I used to below code to see if the keyboard is shown
public static boolean isKeyBoardShown(){
InputMethodManager imm = (InputMethodManager)currentActivity.getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm.isAcceptingText()) {
return true;
} else {
return false;
}
}
-> I know that there is a work around for dialogs in an activity but I can't see one or rework the code to work in a DialogFragment
If neither is possible why does the app get stuck in the wrong UI mode when there is both a shown keyboard and DialogFrament?
1. Explanation for solution.
I have taken the following quotes from the android api docs.
Using Immersive Full-Screen Mode
When immersive full-screen mode is enabled, your activity continues to
receive all touch events. The user can reveal the system bars with an
inward swipe along the region where the system bars normally appear.
This clears the SYSTEM_UI_FLAG_HIDE_NAVIGATION flag (and the
SYSTEM_UI_FLAG_FULLSCREEN flag, if applied) so the system bars become
visible. This also triggers your
View.OnSystemUiVisibilityChangeListener, if set.
Firstly, you don't need an OnSystemUiVisibilityChangeListener when using sticky immersion.
However, if you'd like the system bars to automatically hide again
after a few moments, you can instead use the
SYSTEM_UI_FLAG_IMMERSIVE_STICKY flag. Note that the "sticky" version
of the flag doesn't trigger any listeners, as system bars temporarily
shown in this mode are in a transient state.
The recommendations for using sticky/non sticky immersion:
If you're building a truly immersive app, where you expect users to
interact near the edges of the screen and you don't expect them to
need frequent access to the system UI, use the IMMERSIVE_STICKY flag
in conjunction with SYSTEM_UI_FLAG_FULLSCREEN and
SYSTEM_UI_FLAG_HIDE_NAVIGATION. For example, this approach might be
suitable for a game or a drawing app.
However, you mention users needing the keyboard, so I suggest this:
Use Non-Sticky Immersion
If you're building a book reader, news reader, or a magazine, use the
IMMERSIVE flag in conjunction with SYSTEM_UI_FLAG_FULLSCREEN and
SYSTEM_UI_FLAG_HIDE_NAVIGATION. Because users may want to access the
action bar and other UI controls somewhat frequently, but not be
bothered with any UI elements while flipping through content,
IMMERSIVE is a good option for this use case.
2. Solution
My solution is to set up your view ui in the onActivityCreated of your fragments.
My example taken from ImmersiveModeFragment.java sample.
#Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
final View decorView = getActivity().getWindow().getDecorView();
decorView.setOnSystemUiVisibilityChangeListener(
new View.OnSystemUiVisibilityChangeListener() {
#Override
public void onSystemUiVisibilityChange(int i) {
hideSystemUI();
}
});
}
Create a separate method to manage the ui that you call from your OnSystemUiVisibilityChangeListener()
Taken from here non sticky immersion
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);
}
You can then call this method again onResume.
onResume(){
hideSystemUI();
}
3. Alternate solution.
If sticky immersion is what you really want you need to try a different approach.
For sticky immersion
#Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (hasFocus) {
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);}
}
I hope this solves your problems.
I know this is old but I was struggling with this for a while as I had dialogFragments and a drop down in my navigationView that kept revealing the system UI needlessly. Here are the things I did that ended up working (the first two pieces I found a lot of places):
In my AndroidManifest.xml on the application
android:theme="#style/AppTheme.NoActionBar"
In my activity
View decorView = getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
decorView.setSystemUiVisibility(uiOptions);
And what ended up being the key for me is in my styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
</style>
</resources>
Is it possible to stop the softkeyboard for changing the UI mode?
Maybe
Is it possible to stop the showing of DialogsFraments from changing the UI mode?
Yes if only you try to understand what you are doing
If neither is possible why does the app get stuck in the wrong UI mode when there is both a shown keyboard and DialogFrament?
because of the answer on question 2
now this is your overall solution
The current/Focused View is who the os takes UI visibility settings from,when a View is obscured or is not on top in respect to the z-order then setSystemUiVisibility() is set to its default. So instead try hacking around
View decorView = getWindow().getCurrentFocus() != null ?
getWindow().getCurrentFocus() :getWindow().getDecorView();
and whenever your DialogFragment is dismissed check for the above line and re-call your accessibility ui codes; because .... guess is lucid to this point
In Dialog or BottomSheetDialogFragment you have to implement this solution which is work for me.
Step 1:
In your dialog or BottomSheetDialog, write this code in onActivityCreated method,
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
var viewParent = view
while (viewParent is View) {
viewParent.fitsSystemWindows = false
viewParent.setOnApplyWindowInsetsListener { _, insets -> insets }
viewParent = viewParent.parent as View?
}
}
Step 2: Also, override the below method :
override fun setupDialog(dialog: Dialog, style: Int) {
super.setupDialog(dialog, style)
dialog?.window?.setFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)
}
Now see the magic :)
This fix, plus another fix related to the soft keyboard is included in the DialogFragment class from this library. Just extend this instead of the standard library:
https://github.com/marksalpeter/contract-fragment
The main purposes of the library is to add delegate functionality to Fragments and DialogFragments that leverage the parent/child fragment relationship, but you can just use the bug fix or copy/paste the file
I'm having some issues returning from Immersive Mode in an ActionBarActivity. I have created a simple app to illustrate this issue. There is a layout with a single button to toggle immersive mode. When "returning" from immersive mode, the action bar is offset downwards from its original position, roughly the same distance again that it is usually offset from the top of the screen.
I've tried this on a Nexus 4 running Lollipop. This behavior did not happen pre-Lollipop.
Screenshots before, immersed, after.
A simple ActionBarActivity that illustrates this issue:
public class MainActivity extends ActionBarActivity {
private boolean immersed;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#TargetApi(Build.VERSION_CODES.KITKAT)
private void enterImmersiveMode() {
if(android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
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
);
immersed = true;
}
}
#TargetApi(Build.VERSION_CODES.KITKAT)
private void leaveImmersiveMode() {
if(android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
immersed = false;
// recreate();
}
}
public void toggleImmersive(View v) {
if (immersed) {
leaveImmersiveMode();
} else {
enterImmersiveMode();
}
}
}
Nothing fancy in the manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.immersivetest"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="ImmersiveTest"
android:theme="#style/Theme.AppCompat" >
<activity
android:name=".MainActivity"
android:label="ImmersiveTest" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Trivial layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.immersivetest.MainActivity" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="toggle immersive"
android:onClick="toggleImmersive"
/>
</RelativeLayout>
The workaround I use at the moment is to call recreate() after leaving immersive mode, but it looks a bit "glitchy".
If I up the minSdkVersion and use Activity instead of ActionBarActivity, i.e. don't use the support library, then I do not experience this behavior.
I understand that immersive mode is only available in KitKat+ and that I don't need to use the ActionBarActivity from the support library, but the finished product will have to run on API versions 8+ and the immersive mode is an optional extra.
Some other workarounds I have thought about and dismissed for now:
Have a wrapper launcher Activity which immediately forwards programmatically to an ActionBarActivity for lower API versions.
Have multiple apps by API version.
Either of those options sounds like a lot of added maintenance.
Is there anything else I could try? Are there any glaring mistakes in the code above, with respect to returning from immersive mode?
Update
I have since updated the Nexus 4 to 5.1 and the support library to rev 22.1.1 and the behavior is still the same. I have also updated the code to use the new AppCompatActivity since ActionBarActivity is now deprecated. The behavior is, once more, the same.
public class MainActivity extends AppCompatActivity {
// no changes here
}
Update
This weird behavior also extends to the landscape mode. In addition to the offset at the top of the screen, there also is an offset to the right of the screen between the end of the action bar and the navigation buttons. Interestingly this offset again seems to be the size of the navigation button "bar", i.e. larger than the offset at the top.
Landscape screenshots before, immersed, after.
Had the same problem, fixed with this:
your leaveImmersiveMode() function should use these flags instead:
getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_FULLSCREEN);
Use a Toolbar ... I had the same problem and switching to a Toolbar instead of a customContentView solved it.
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
And set your Activity's theme to #style/Theme.AppCompat.NoActionBar
Notwithstanding the fact that ActionBarActivity was deprecated in the support library from V26, changing your leaveImmersiveMode() method to specify the following flags fixes the problem for me with the test app using your code (which originally showed the extra gap you mentioned).
#TargetApi(Build.VERSION_CODES.KITKAT)
private void leaveImmersiveMode() {
if(android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
immersed = false;
// recreate();
}
}
These are the flags recommended in the Android documentation on immersive mode.
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 created a launcher, to use it in an internal application. for some security reasons i would like to hide the system bar (the acces to the parameter an ordrer to the acces to installed application). But i have no idea how to do this.
Tablet that will be used are not rooted.
Can you help me please?
You can't hide it but you can disable it, except home. For that you can give your application as home category and let the user choose.
<category android:name="android.intent.category.HOME" />
Rest all can be disable.
add this in manifest.
<uses-permission android:name="android.permission.EXPAND_STATUS_BAR"/>
inside onCreate()
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_home);
View v = findViewById(R.id.home_view);
v.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
where home_view is the parent view of xml file.
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
return false;
}
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)
{
}
}
You can hide the bottom bar I used this code to hide:
getWindow().getDecorView().setSystemUiVisibility(View.GONE);
use this code for android box with keyboard or remote.
Tablet that will be used are not rooted
Then you can't hide it. You can however use SYSTEM_UI_FLAG_HIDE_NAVIGATION to hide it temporary, but it will get visible once the user touches the screen:
There is a limitation: because navigation controls are so important,
the least user interaction will cause them to reappear immediately.
When this happens, both this flag and SYSTEM_UI_FLAG_FULLSCREEN will
be cleared automatically, so that both elements reappear at the same
time.
You can hide the navigation bar on Android 4.0 and higher using the SYSTEM_UI_FLAG_HIDE_NAVIGATION flag. This snippet hides both the navigation bar and the status bar:
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
See the following: Hiding the Navigation Bar
Put this in your onCreate() method:
requestWindowFeature(Window.FEATURE_NO_TITLE);
EDIT: Hiding the status bar would require your application be full screen or rooted.