Reputation: 1634
I referred this link. In that if the user clicks on EditText(for ex To: ) at that time keyboard will be popped out and at the same time the user can be able to scroll to see all remaining views(ex: compose,subject, send button) in that screen. Similarly in my app I have one activity in that I am having some widgets or views.
Suppose if the user clicks on Edittext which is in my Activity then keyboard is popping out and i can be able to scroll to see remaining views. But if i give this attribute android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
in manifest i was unable to scroll to see remaining views but if give attribute android:theme="@android:style/Theme.NoTitleBar"
like this in manifest I can be able to scroll to see remaining view but there is status bar in that screen, here I want full screen and even if the keyboard is popped out I can scroll to see remaining views..? what changes I have to made for this..?
Upvotes: 137
Views: 285683
Reputation: 150
class ActivityOnboarding : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val binding = ActivityOnboradingBinding.inflate(layoutInflater)
enableEdgeToEdge()
setContentView(binding.getRoot())
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
v.setPadding(0, 0, 0, systemBars.bottom)
insets
}
}
}
try this enableEdgeToEdge() and setOnApplyWindowInsetsListener v.setPadding(0, 0, 0, systemBars.bottom)
Upvotes: 0
Reputation: 273
Always put this before setContentView
to avoid app crashing.
requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
Upvotes: 0
Reputation: 31
100% it's will work for Hide and show statusbar & navigationbar
Call this methods directly for show and hide statusbar * navigationbar
private void hideSystemUI() {
View decorView = getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
decorView.setSystemUiVisibility(uiOptions);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
private void showSystemUI() {
View decorView = getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
For mor info Rajmeetamil
Upvotes: 0
Reputation: 255
If you are working with higher API then you may have noticed the flags as mentioned by the above answers i.e. FLAG_FULLSCREEN
and SYSTEM_UI_FLAG_FULLSCREEN
are deprecated.
To cover up the whole screen you can define a custom theme:
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="ActivityTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowFullscreen">true</item>
</style>
</resources>
Add the theme in your activity in the manifest
like android:theme="@style/ActivityTheme"
and you are done.
Note: You can also add pre-defined @android themes directly in your manifest: android:theme="@android:style/Theme.Holo.NoActionBar.Fullscreen"
.
In such cases make sure your activity extends Activity()
not AppCompatActivity()
although it's not recommended.
Upvotes: 11
Reputation: 136
Add the following code to themes.xml file. it will make the notification drawer semi-transparent.
<item name="android:windowTranslucentStatus">true</item>
Upvotes: 0
Reputation: 61
Here How you can hide the status bar Use this function in your Helper Object Class and call it in your activity
fun hideStatusBar(window: Window, context: Context){
if (SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
window
.decorView
.systemUiVisibility =
View.SYSTEM_UI_FLAG_LAYOUT_STABLE or
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
window.statusBarColor = ContextCompat.getColor(context, R.color.transparent_bg_color)
} else {
window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN)
}
}
Call it in your Activity before set Content View.
hideStatusBar(window, this)
setContentView(R.layout.activity_detail)
Upvotes: 0
Reputation: 3458
Hide StatusBar
private void hideSystemBars() {
WindowCompat.setDecorFitsSystemWindows(getWindow(), false);
WindowInsetsControllerCompat windowInsetsController = ViewCompat.getWindowInsetsController(getWindow().getDecorView());
if (windowInsetsController == null) {
return;
}
// Configure the behavior of the hidden system bars
windowInsetsController.setSystemBarsBehavior(WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE);
// Hide both the status bar and the navigation bar
windowInsetsController.hide(WindowInsetsCompat.Type.systemBars());
}
show StatusBar
private void showSystemBars() {
WindowCompat.setDecorFitsSystemWindows(getWindow(), false);
WindowInsetsControllerCompat windowInsetsController = ViewCompat.getWindowInsetsController(getWindow().getDecorView());
if (windowInsetsController == null) {
return;
}
// Configure the behavior of the hidden system bars
windowInsetsController.setSystemBarsBehavior(WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE);
// Hide both the status bar and the navigation bar
windowInsetsController.show(WindowInsetsCompat.Type.systemBars());
}
for top camera cut with screen
<item name="android:windowLayoutInDisplayCutoutMode" tools:ignore="NewApi">shortEdges</item>
Upvotes: 3
Reputation: 30765
The clean and scalable approach to show and hide system UI I stick to, which works for different Android Api levels:
object SystemBarsCompat {
private val api: Api =
when {
Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> Api31()
Build.VERSION.SDK_INT == Build.VERSION_CODES.R -> Api30()
else -> Api()
}
fun hideSystemBars(window: Window, view: View, isImmersiveStickyMode: Boolean = false) =
api.hideSystemBars(window, view, isImmersiveStickyMode)
fun showSystemBars(window: Window, view: View) = api.showSystemBars(window, view)
fun areSystemBarsHidden(view: View): Boolean = api.areSystemBarsHidden(view)
@Suppress("DEPRECATION")
private open class Api {
open fun hideSystemBars(window: Window, view: View, isImmersiveStickyMode: Boolean = false) {
val flags = View.SYSTEM_UI_FLAG_FULLSCREEN or
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
view.systemUiVisibility = if (isImmersiveStickyMode) {
flags or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
} else {
flags or
View.SYSTEM_UI_FLAG_IMMERSIVE or
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
}
}
open fun showSystemBars(window: Window, view: View) {
view.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
}
open fun areSystemBarsHidden(view: View) = view.systemUiVisibility and View.SYSTEM_UI_FLAG_HIDE_NAVIGATION != 0
}
@Suppress("DEPRECATION")
@RequiresApi(Build.VERSION_CODES.R)
private open class Api30 : Api() {
open val defaultSystemBarsBehavior = WindowInsetsController.BEHAVIOR_SHOW_BARS_BY_SWIPE
override fun hideSystemBars(window: Window, view: View, isImmersiveStickyMode: Boolean) {
window.setDecorFitsSystemWindows(false)
view.windowInsetsController?.let {
it.systemBarsBehavior =
if (isImmersiveStickyMode) WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
else defaultSystemBarsBehavior
it.hide(WindowInsets.Type.systemBars())
}
}
override fun showSystemBars(window: Window, view: View) {
window.setDecorFitsSystemWindows(false)
view.windowInsetsController?.show(WindowInsets.Type.systemBars())
}
override fun areSystemBarsHidden(view: View) = !view.rootWindowInsets.isVisible(WindowInsets.Type.navigationBars())
}
@RequiresApi(Build.VERSION_CODES.S)
private class Api31 : Api30() {
override val defaultSystemBarsBehavior = WindowInsetsController.BEHAVIOR_DEFAULT
}
}
And for example to hide system bars, it can be called from a Fragment
:
SystemBarsCompat.hideSystemBars(requireActivity().window, view)
Upvotes: 2
Reputation: 1362
If you are using Compose then you can import
implementation "com.google.accompanist:accompanist-systemuicontroller:0.17.0"
then in your screen just write
val systemUiController = rememberSystemUiController()
systemUiController.isStatusBarVisible = false
Upvotes: 0
Reputation: 135
I know I'm very late to answer. I use the following piece of code in a relative java file for this purpose
Objects.requireNonNull(getSupportActionBar()).hide();
Upvotes: 0
Reputation: 758
We can hide status bar in Android 4.1 (API level 16) and higher by using setSystemUiVisibility()
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_FULLSCREEN
As per google document we should never show the action bar if the status bar is hidden, so hide that too if necessary.
actionBar?.hide()
Upvotes: 0
Reputation: 768
Add or Replace in Style.xml File
<item name="android:statusBarColor">@android:color/transparent</item>
Upvotes: 0
Reputation: 939
this is the best solution for me , just write this line in your theme.xml
<style name="MyApp" parent="Theme.AppCompat.Light.NoActionBar">
...
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
...
</style>
Upvotes: 5
Reputation: 131
including android api 30, this works for me
if (Build.VERSION.SDK_INT < 16) {
window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN)
} else if (Build.VERSION.SDK_INT < 30) {
window.decorView?.systemUiVisibility = View.SYSTEM_UI_FLAG_FULLSCREEN
actionBar?.hide()
} else {
window.decorView.windowInsetsController?.hide(WindowInsets.Type.statusBars())
}
Upvotes: 2
Reputation: 637
As FLAG_FULLSCREEN is deprecated from android R. You can use below code to hide status bar.
@Suppress("DEPRECATION")
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
window.insetsController?.hide(WindowInsets.Type.statusBars())
} else {
window.setFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN
)
}
Upvotes: 4
Reputation: 2066
If you refer to the Google Documents you can use this method for android 4.1 and above, call this method before setContentView()
public void hideStatusBar() {
View view = getWindow().getDecorView();
int uiOption = View.SYSTEM_UI_FLAG_FULLSCREEN;
view.setSystemUiVisibility(uiOption);
ActionBar actionBar = getActionBar();
if (actionBar != null) {
actionBar.hide();
}
}
Upvotes: 0
Reputation: 2330
If you are hiding the status bar do this in onCreate(for Activity) and onCreateView/onViewCreated(for Fragment)
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
And don't forget to clear the flag when exiting the activity or else you will have the full screen in your whole app after visiting this activity. To clear do this in your onDestroy(for Activity) or onDestroyView(for Fragment)
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN)
Upvotes: 10
Reputation: 751
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTheme(R.style.Theme_AppCompat_Light_NoActionBar);
requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN
, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity__splash_screen);
}
Upvotes: 2
Reputation:
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
Upvotes: -1
Reputation: 1042
Use this code for hiding the status bar in your app and easy to use
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
Upvotes: 24
Reputation: 1061
You can hide status bar by setting it's color to transperant using xml. Add statusBarColor item to your activity theme:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:statusBarColor">@android:color/transparent</item>
</style>
Upvotes: 4
Reputation: 4940
Add this to your Activity class
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);
// some your code
}
Upvotes: 12
Reputation: 159
You can hide by using styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="HiddenTitleTheme" parent="AppTheme">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
</style>
just call this in your manifest like this android:theme="@style/HiddenTitleTheme"
Upvotes: 5
Reputation: 1244
In AndroidManifest.xml -> inside the activity which you want to use, add the following:
android:theme="@style/Theme.AppCompat.Light.NoActionBar"
//this is for hiding action bar
and in MainActivity.java -> inside onCreate() method, add the following :
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
//this is for hiding status bar
Upvotes: 5
Reputation:
Under res -> values ->styles.xml
Inside the style body tag paste
<item name="android:windowTranslucentStatus" tools:targetApi="kitkat">true</item>
Upvotes: -1
Reputation: 490
Used in Manifest
android:theme="@android:style/Theme.Holo.NoActionBar.Fullscreen"
Upvotes: 0
Reputation: 7046
Use this code:
requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
super.onCreate(savedInstanceState);
setContentView(R.layout.youractivityxmlname);
Upvotes: 5
Reputation: 5288
Change the theme of application in the manifest.xml
file.
android:theme="@android:style/Theme.Translucent.NoTitleBar"
Upvotes: 6
Reputation: 4480
Write this in your Activity
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
Check Doc here : https://developer.android.com/training/system-ui/status.html
and your app will go fullscreen. no status bar, no title bar. :)
Upvotes: 199
Reputation: 2392
void hideStatusBar() {
if (Build.VERSION.SDK_INT < 16) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
} else {
View decorView = getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
}
}
You can use this method to hide the status bar. And this is important to hide the action bar too. In this case, you can getSupportActionBar().hide() if you have extended the activity from support lib like Appcompat or you can simply call getActionBar().hide() after the method mentioned above. Thanks
Upvotes: 7