android java disable touch screen home button - java

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);
}

Related

How to keep hiding bottom navigation bar when SearchView is touched/focused or Dialog is showed/focused - AndroidStudio/Java

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 ?

How can I hide Navigation Bar without hiding the status bar

I am trying to hide the Bottom navigation bar only and not the status bar. Most of the code I am getting is hiding both the navigation bar and the status bar.
Try the below function. Owing to changes in Android R, View.SYSTEM_UI_FLAG_HIDE_NAVIGATION, setSystemUiVisibility etc are being deprecated. I have made the function to handle this scenario.
public void hideBottomNavigationBar() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
getWindow().setDecorFitsSystemWindows(false);
WindowInsetsController controller = getWindow().getInsetsController();
if(controller != null) {
controller.hide(WindowInsets.Type.navigationBars());
controller.setSystemBarsBehavior(WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE);
}
} else {
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
}
}
Another thing to note about using View.SYSTEM_UI_FLAG_HIDE_NAVIGATION from the docs:
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.
Inorder to work around this limitation you can set View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY as well like this:
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
But this only works SDK 19 onwards.
View v = getWindow().getDecorView();
int options = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN;
v.setSystemUiVisibility(options);

How to have full-screen despite the notch?

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

Android full screen on only one activity?

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

How To gone (not invisible) NavigationBar?

I try to hide NavigationBar by this code:
public static void setFullscreen(final View decorView) {
decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {
#Override
public void onSystemUiVisibilityChange(int visibility) {
if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
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);
}
}
});
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) {
decorView.setSystemUiVisibility(decorView.getSystemUiVisibility());
}
}
And for each Activity:
#Override
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);}
}
And theme of activities :
<style name="Theme.AppCompat.Light.NoActionBar.FullScreen" parent="#style/Theme.AppCompat.Light">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">true</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">#null</item>
</style>
I success to hide NavifationBar , but NavigationBar just invisible , not gone!
So real question is How to gone Navigation bar?
sorry for my poor English.
you dont need a separate query just to get the current time via NOW() you can incorporate it in your query
DELETE FROM current_questions WHERE createTime > NOW() - INTERVAL 1 MINUTE
that's createTime greater than a minute ago.
Also its important to know that The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead
mysql_query function returns a resource.
you still need to go and fetch the data from the resource
$serverTime = mysql_query("SELECT NOW()") or die(mysql_error());
$data = mysql_fetch_array($serverTime);
$serverTime = $data[0]; // and from now it should work.
mysql_query("DELETE FROM current_questions WHERE TIMESTAMPDIFF( MINUTE ,`createTime`,'$serverTime')")or die(mysql_error());
The other answer is better, but it's good to go back and learn from your own mistakes step by step.
Another thing, you should use mysqli extension instead of mysql. That one is older and soon will be deprecated.
Resources:
http://php.net/manual/en/function.mysql-fetch-array.php
http://php.net/manual/en/function.mysql-query.php

Categories