Can someone please help me with the issue.I want my activity as full screen and want to remove title from the screen.I have tried several ways but not able to remove it.
Activity Code :
public class welcomepage extends Activity {
private Button btn;
EditText userName,passWord;
DatabaseHandler dbHandler;
Context ctx =this;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Remove title bar
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_welcomepage);
}
}
And Activity.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:background="#drawable/pic1"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.edkul.vimal.edkul.welcomepage">
</RelativeLayout>
I want to remove the title bar displayed in blue color .Please find the image for the reference :
AndroidManifest.xml
<application
android:minSdkVersion="3"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/Theme.AppCompat.NoActionBar">
<activity
android:name=".welcomepage"
android:label="#string/app_name"
android:theme="#style/Theme.AppCompat.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
you just add this style in your style.xml file which is in your values folder
<style name="AppTheme.NoActionBar" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
</style>
After that set this style to your activity class in your AndroidManifest.xml file
android:theme="#style/AppTheme.NoActionBar"
Edit:- If you are going with programmatic way to hide ActionBar then use below code in your activity onCreate() method.
if(getSupportedActionbar()!=null)
this.getSupportedActionBar().hide();
and if you want to hide ActionBar from Fragment then
getActivity().getSupportedActionBar().hide();
AppCompat v7:-
Use following theme in your Activities where you don't want actiobBar Theme.AppComat.NoActionBar or Theme.AppCompat.Light.NoActionBar or if you want to hide in whole app then set this theme in your <application... /> in your AndroidManifest.
In Kotlin:
add this line of code in your onCreate() method or you can use above theme.
supportActionBar?.hide()
i hope this will help you more.
Try this:
this.getSupportActionBar().hide();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try
{
this.getSupportActionBar().hide();
}
catch (NullPointerException e){}
setContentView(R.layout.activity_main);
}
You can try:
<activity android:name=".YourActivityName"
android:theme="#style/Theme.Design.NoActionBar">
that works for me
In your Android Manifest file make sure that the activity is using this (or a) theme (that is based on) #style/Theme.AppCompat.NoActionBar
This removes the ActionBar completely, but won't make your activity fullscreen.
If you want to make your activity fullscreen only use this theme
#android:style/Theme.NoTitleBar.Fullscreen
Or you could change
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
to
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
This is what I use to get fullscreen at runtime
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
mDecorView = getWindow().getDecorView();
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);
}
To exit fullscreen I use this
mDecorView = getWindow().getDecorView();
mDecorView.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
Add in activity
requestWindowFeature(Window.FEATURE_NO_TITLE);
and add your style.xml file with the following two lines:
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
You just add following lines of code in style.xml file
<style name="AppTheme.NoTitleBar" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
change apptheme in AndroidManifest.xml file
android:theme="#style/AppTheme.NoTitleBar"
For Kotlin you only need this line:
this.actionBar?.hide()
You may use it before setting your content for example:
super.onCreate(savedInstanceState)
//this line is important
this.actionBar?.hide()
setContent {
Box(Modifier.fillMaxSize()) {
.
.
.
You do not need any other changes on XML
Add this two line in your style.xml
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
Related
To make the Full-Screen Activity,
So far I have tried it as below :
requestWindowFeature(Window.FEATURE_NO_TITLE)
before setContentView() method in Activity.
Also Tried adding below lines :
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN)
But it not worked. Then, I have moved to manifest and Tried as below :
android:theme="#style/Theme.AppCompat.Light.NoActionBar.FullScreen"
<activity
android:theme="#style/Theme.AppCompat.Light.NoActionBar.FullScreen"
android:name="SplashActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
and the stype I have tried above is as below :
<style name="Theme.AppCompat.Light.NoActionBar.FullScreen" parent="#style/Theme.AppCompat.Light">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
</style>
And Yes, In my layout the Root tag is as below :
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:background="#drawable/bg_layout_screen">
means using android:fitsSystemWindows="true"
Now, the issue is It's not visible as full-screen activity.
The issue screenshot is as below :
[![enter image description here][1]][1][![enter image description here][2]][2]
But Still, the issue is as below Image.
First Image :
[1]: https://i.stack.imgur.com/fbJ2l.jpg
Second Image :
[2]: https://i.stack.imgur.com/ZTpgw.jpg
Black is while adding this line in manifest :
android:theme="#style/Theme.AppCompat.Light.NoActionBar.FullScreen"
Please guide. What might be the issue? Thanks.
As per your first image you have to just change the color of your status bar to transperent.
To do it please refer below post
Android Completely transparent Status Bar?
Hope this post helpful to you :)
You can use onWindowFocusChanged() and View decorView = getWindow().getDecorView(); then set SystemUiVisibility.
Example:
//set full screen
#Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (hasFocus) {
hideSystemUI();
}
}
private void hideSystemUI() {
View decorView = getWindow().getDecorView();
decorView.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
// content doesn't resize when the system bars hide and show.
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
// Hide the nav bar and status bar
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
);
}
I have configured my application and activities to work on full screen mode, but I'm finding with a problem I can't solve.
When my App starts up it goes from a loading screen to home screen, everything ok, but If I press "home" button and comeback to my App (no loading screen now, app it's started) then the layout is displaced by the status bar, and my bottom bar is cut. This effect lasts like 0.5-1 sec.
This also happens when a heads up notifications shows up.
My research points to listviews or similiar views, like viewpager.
It just happened on my activities with listviews, then I changed my activity to manage fragments on a view pager, tried again and now happens in every single fragment, I mean my 3rd page is a simple fragment and it didn't happen on that one, but now with view pager it does.
I have all my activies with the same theme on manifest:
<activity
android:name=".OpenActivity"
android:screenOrientation="portrait"
android:theme="#style/AppTheme.FullScreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
styles.xml
<style name="AppTheme.FullScreen" parent="Theme.AppCompat.Light.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowEnableSplitTouch">false</item>
</style>
main_activity.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:background="#android:color/transparent">
<androidx.viewpager2.widget.ViewPager2
android:id="#+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/navbar_space" />
<fragment
android:id="#+id/nav_bar_fragment"
android:name="es.udc.psi1516.pickapp.navbar.NavBarFragment"
android:layout_width="match_parent"
android:layout_height="#dimen/navbar_height"
android:orientation="horizontal"
android:layout_alignParentBottom="true" />
</RelativeLayout>
I have some code on my MainActivity.java to hide status bar:
#Override
protected void onResume() {
super.onResume();
hideSystemUI();
}
// This snippet hides the system bars
public void hideSystemUI() {
int newUiOptions = getWindow().getDecorView().getSystemUiVisibility();
newUiOptions ^= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
newUiOptions ^= View.SYSTEM_UI_FLAG_FULLSCREEN;
newUiOptions ^= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
getWindow().getDecorView().setSystemUiVisibility(newUiOptions);
}
And it only happens when you enter the App from App Icon, if you comeback from android task view it works nice. I gave up but if you have any ideas I would try anything.
After a lot of testing I have found the solution.
I have had to remove the fullscreen property from xml styles, that was applying some internal states that broke my app screen.
And now I have to manage the state just in code.
Remove android:fitsSystemWindows="true" so my layout doesn't leave extra space for status bar.
Remove android:windowFullscreen from style, now it looks like this:
<style name="AppTheme.FullScreen" parent="Theme.AppCompat.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
Change code of flags to override current state on onResume(), I was adding flags to current state, don't ask me why, probably some copy-paste fail:
private void hideSystemUI() {
int newUiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
getWindow().getDecorView().setSystemUiVisibility(newUiOptions);
}
I've successfully set the app in the immersive mode because I want to hide the status bar (on the top screen) and the navigation bar (on the bottom screen).
The problem is that when the activity changes the bottom bar automatically arise and immediately after go down and disappear.
I want to avoid this.
All activities have the style AppTheme.NoActionBar set in the manifest:
android:theme="#style/AppTheme.NoActionBar"
And in the OnCreate all have the following code:
getWindow().getDecorView().getViewTreeObserver().addOnGlobalLayoutListener(
new ViewTreeObserver.OnGlobalLayoutListener() {
#Override
public void onGlobalLayout() {
GlobalFunctions.setFullscreen(getWindow().getDecorView());
}
});
Where this is the setFullscreen() function:
public static void setFullscreen(View decorView){
int ui_Options = 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(ui_Options);
}
Should I set these attributes before the onCreate in the activity lifecycle? or there are other solutions? or I've implemented the immersive mode in the wrong way?
You don't need to set the global layout listener. Just invoke the setFullscreen function before super.onCreate()
Use this code in manifest activity tag
android:theme="#style/AppFullScreenTheme"
create this style in style.xml
<style name="AppFullScreenTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:fontFamily">#font/montserrat</item>
<item name="android:windowContentOverlay">#null</item>
</style>
else use this in your activity class
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
this worked for me.
I have a layout A. When i enter to layout A, i want title app or actionbar will be hide.
i have searched in Google.
<style name="AppTheme.Fullscreen">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
</style>
But it must do in AndroidManifest.xml
(My app have many screen, and just only layout A, action bar will hide.)
So, i find a way which can set up it into file layout A?
How can i do that ?
use getSupportActionBar().hide(); to hide your action bar programtically
getSupportActionBar().hide();
if you want fullscreen activity than use below code
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.activity_main);
}
Or you can do it via your AndroidManifest.xml file:
<activity android:name=".YourActivity"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"/>
How do I do this? Any suggestions? BTW I am using SDK with AIDE.
Go into the manifest and use a full screen theme.
<activity
android:name=".Foo"
android:label="#string/foo"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen">
This code makes the current Activity Full-Screen. No Status-Bar or anything except the Activity-Window!
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);
}
}
Edit for AppCompactActivity
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/orange</item>
<item name="colorPrimaryDark">#android:color/holo_orange_dark</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
</style>
If you want a full screen put this attribute in <activity /> or <application /> tag in your Manifest file
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
Agree with the above answer given by SquiresSquire. Just adding little more information in the answer i would like to present my answer.
You can make your application full screen in two ways,
Making Full Screen any particular Activity
add theme element in activity tag
<activity
android:name=".YourActivityName"
android:theme="#android:style/Theme.NoTitleBar.">
Making Full Screen whole application
add theme element with application tag
<application
android:icon="#drawable/icon"
android:theme="#android:style/Theme.NoTitleBar.">
To set your Application or any individual activity display in Full Screen mode,
Insert the code in AndroidManifest .xml file
#android:style /Theme. NoTitle Bar.Fullscreen
This works well for me.
android:theme="#style/Theme.AppCompat.NoActionBar"