My app has 3 activities(activity_main,activity_one,activity_two).
I want to full screen only the first activity so I searched and I found out I got to use this:
View decorView = getWindow().getDecorView();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
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);
}
When I go to the other activities that are not full screen and press the back button and go back to main activity the home button back button is there hiding the bottom of my main activity.How do I solve this?
Also if possible I would like to know how can I make my activity full screen but keep the action bar.
edit:
Im asking for a full screen on one activity and not the other two(except if the action bar stays).If i go on activity_two (which is not full screen) i have the home button back button etc .If i press the back button and go back to the main activity the buttons stay there which i don't want to (not only because i want my main full screen but because the buttons from activity two stay and hide the bottom of my main activity)
As onWindowsFocusChanged() is what you need so try this:1. First, Declare this variable as global in your MainActivity
private int currentApiVersion;
2. then paste this code in onCreate() of that activity.
currentApiVersion = Build.VERSION.SDK_INT;
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_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
if (currentApiVersion >= Build.VERSION_CODES.KITKAT) {
getWindow().getDecorView().setSystemUiVisibility(flags);
final View decorView = getWindow().getDecorView();
decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {
#Override
public void onSystemUiVisibilityChange(int visibility) {
if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
decorView.setSystemUiVisibility(flags);
}
}
});
}
3. Now paste this method in your MainActivity class.
#SuppressLint("NewApi")
#Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (currentApiVersion >= Build.VERSION_CODES.KITKAT && hasFocus) {
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_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
}
}
Now this should work, give it a try.
You can do this in two ways,
Programmatically -- Set FullScreen flag to window of activity inside onCreate() method (just after or before setContentView()). Whom you want to be fullscreen. For example,
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
Window w = getWindow();
w.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
Or you can set theme in your AndroidManifest.xml as,
<activity
android:name=".YourActivityName"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"/>
Or If you are using AppCompatActivity then you can set as,
<activity
android:name=".YourActivityName"
android:theme="#android:style/Theme.AppCompat.Light.NoActionBar"/>
For more info about the window flags check this link https://developer.android.com/reference/android/view/WindowManager.LayoutParams.html
Related
I call this function in onCreate of every activity of my app project:
public void hideDeviceBottomNav ()
{
View decorView = getWindow().getDecorView();
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;
decorView.setSystemUiVisibility(flags);
decorView.setOnSystemUiVisibilityChangeListener
(new View.OnSystemUiVisibilityChangeListener() {
#Override
public void onSystemUiVisibilityChange(int visibility) {
// Note that system bars will only be "visible" if none of the
// LOW_PROFILE, HIDE_NAVIGATION, or FULLSCREEN flags are set.
if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
// TODO: The system bars are visible. Make any desired
// adjustments to your UI, such as showing the action bar or
// other navigational controls.
decorView.setSystemUiVisibility(flags);
} else {
// TODO: The system bars are NOT visible. Make any desired
// adjustments to your UI, such as hiding the action bar or
// other navigational controls.
}
}
});
}
and still every time I touch the search icon in my SearchView to search in my ListView or create and show new custom Dialog, the bottom navigation bar appears... .
In addition, how can I hide the bottom navigation only without hiding the upper bar ?
I want an activity to be fullscreen despite the notch so that at its sides the screen is useful. Please does anyone know how to do it?
I guess it must be a different theme or something like that.
There is a fix for this given by Android Pie Apis.
Follow the following steps:-
1) Create a new values-v28 folder in your res directory and copy the default styles.xml file into it.
Create new or edit existing theme
<style name="ActivityTheme">
<item name="android:windowLayoutInDisplayCutoutMode">
shortEdges
</item>
</style>
There are 3 possible values for android:windowLayoutInDisplayCutoutMode ie - default,shortEdges and never . Try each to know the difference between them .
Doing this programmaticaly inside a activity which is what worked for me instead of defining a style will be as follows:
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
getWindow().getAttributes().layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
}
This code is what changes the whole scenario for devices with notch display
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
getWindow().getAttributes().layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
}
Also, if by any chance you still see the system ui the use the following code along with the above code
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE
| View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
Try adding this in your activity
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
This makes the activity full screen by removing navigation and status bars
im creating apps with slider on the first run, but seems, android home button covers my layout.
how can i hide touch screen home button?
thanks
i try use this code but not working :
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
i try use padding bottom but its show some space on device that not use touch screen home button.
any body experience this?
Use the below code to hide the navigation 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
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
decorView.setSystemUiVisibility(uiOptions);
Source
Try this code: Android immersive mode will work perfect.
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 // hide nav bar
| View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
| View.SYSTEM_UI_FLAG_IMMERSIVE);
immersive mode android click here
Try this,
public static int getSoftButtonsBarSizePort(Activity activity) {
// getRealMetrics is only available with API 17 and +
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
DisplayMetrics metrics = new DisplayMetrics();
activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
int usableHeight = metrics.heightPixels;
activity.getWindowManager().getDefaultDisplay().getRealMetrics(metrics);
int realHeight = metrics.heightPixels;
if (realHeight > usableHeight)
return ((realHeight - (usableHeight)) / 4);
else
return 0;
}
return 0;
}
and in on create, you have to
RelativeLayout.LayoutParams relativeParams = (RelativeLayout.LayoutParams) layout2.getLayoutParams();
relativeParams.setMargins(0, 0, 0, getSoftButtonsBarSizePort(DimgloActivity.this)); // left, top, right, bottom
layout2.setLayoutParams(relativeParams);
Call this method in onCreate before setting view like this:-
Constants.fullScreen(this); //call before setting view
setContentView(R.layout.activity_generator);
final_tv = (TextView) findViewById(R.id.final_tv);
.
.
And create this function in your Constant, you can comment or remove some lines according to your need
public static void fullScreen(Activity activity)
{
activity.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);
}
I've read up on a lot of questions about immersive sticky mode on Android, but I cannot find a specific answer for my question.
I have read onBackPressed function not working under IMMERSIVE STICKY mode, but my app goes back successfully when an ImageButton is pressed.
I want to remain in immersive sticky mode for the whole duration of the app. There is no problem when I launch a new activity, with and without a shared element transition. However, when I go back, the system bars sometimes appears then soon slide out of view again. This happens especially when I stay on an activity for a while.
This transition is called from _TrickPage.class:
public void setBorroRingsOnClickListener(View view){
dBHelper.close();
Intent intent = new Intent(this, _DominoScene.class);
startActivity(intent);
}
And I call finish() to get back to _TrickPage.class from _Domino.class:
findViewById(R.id.picture).setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View v){
dBHelper.close();
finish();
}
});
Another transition I use is a shared element transition. The following is an inner class of ButtonAdapter, which extends BaseAdapter, an object in my _Submenu Activity:
class MyOnClickListener implements View.OnClickListener {
private final int position;
public MyOnClickListener(int position){
this.position = position;
}
#Override
public void onClick(View v) {
...
//link clicked button to _TrickPage button for shared transition
v.setTransitionName("trick");
//make and start shared transition to _TrickPage
ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(
(Activity)mContext,
new Pair<View, String>(v, "trick")
);
Intent intent = new Intent(v.getContext(), _TrickPage.class);
v.getContext().startActivity(intent, options.toBundle());
}
}
Finally, to get back to _Submenu from _TrickPage, I call finishaftertransition():
picture.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
dBHelper.close();
hideMainContent();
finishAfterTransition();
}
});
I set the UI flags in the onCreate() and onResume() methods of the Activities involved: _Submenu, _TrickPage, and _DominoScene. I also have the following in each activity:
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
//if (hasFocus)
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 (hasFocus && playAnimations) {
//showMainContent();
playAnimations = false;
}
}
This is my first time asking a question on Stack Overflow, so please ask for any other parts of my code if you think there could be a problem there. Thanks!
Call this method on your onCreate method from every Activity(right after your setContentView method). And also on the onWindowsFocusChanged
public void goImmersive()
{
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);
}
Following the tutorials on this page(written in 2009) don't work any more. http://www.androidsnippets.com/how-to-make-an-activity-fullscreen
public class FullScreen extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
}
}
Similarily, trying to change the theme in android.xml has no effect:android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
Here is a screenshot:
After scouring the web for a few hours, i cant find any articles that can help me.
So how, in version 1.5.4 of libgdx, can i get an immersive full screen?
----EDIT----
Here is the now fully working code:
public class AndroidLauncher extends AndroidApplication {
#Override
protected void onCreate (Bundle savedInstanceState) {
hideSystemUi();
super.onCreate(savedInstanceState);
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
config.hideStatusBar=true;
config.useImmersiveMode=true;
initialize(new game(), config);
}
private void hideSystemUi() {
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);
}
}
Try this in the android activity:
#Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (hasFocus) {
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
}
}
Note this will only work on API level 19 or above.
Sadly I can't comment due to my current reputation,
however I have found that adding:
config.hideStatusBar = true;
config.useImmersiveMode = true;
in the AndroidLauncher class is enough to show the app in immersive however the app will start in standard mode and then update to immersive mode, more info on the Android immersive mode:
When you use the SYSTEM_UI_FLAG_IMMERSIVE_STICKY flag, an inward swipe in the system bars areas causes the bars to temporarily appear in a semi-transparent state, but no flags are cleared, and your system UI visibility change listeners are not triggered. The bars automatically hide again after a short delay, or if the user interacts with the middle of the screen.
Android sdk page
So my conclusion would be that config.useImmersiveMode use the sticky flag.
On a side note,
#TargetApi(Build.VERSION_CODES.HONEYCOMB)
has to be added to the OnWindowFocusChanged method when targeting an api lvl less than 11