Android Fullscreen Not Working: Gingerbread - android

I am trying to make a fullscreen activity, but it doesn't seem to work in GingerBread, here is my code
#SuppressLint("NewApi")
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_eyes);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH){
ActionBar actionBar = getActionBar();
actionBar.hide();
}
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD){
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
In Gingerbread there is still a title.
Does anyone know how to fix this?

First of all you should set the activity as full screen in the manifest.
In the desired activity, add this code
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
and your onCreate should be like this
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD){
requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
setContentView(R.layout.main);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH){
ActionBar actionBar = getActionBar();
actionBar.hide();
}
This might solve the problem.

Remember that you must call requestWindowFeature before call setContentView
Try this to make a full screen activity by java:
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
and in Manifest
android:theme="#android:style/Theme.Translucent.NoTitleBar"

requestWindowFeature has to be called before super.onCreate. Like so:
#SuppressLint("NewApi")
#Override
public void onCreate(Bundle savedInstanceState) {
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD){
requestWindowFeature(Window.FEATURE_NO_TITLE);
}
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_eyes);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH){
ActionBar actionBar = getActionBar();
actionBar.hide();
}
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD){
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
// ...
If this doesn't work, move the getWindow().setFlags(...) call to the top as well.

Unless you have a reason to not setting it in your manifest, add this attribute to your tag in the Manifest:
<application
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
.....
>
And I believe you wouldn't need the if-conditions code in the onCreate().

isn't just android:theme ="#android:style/Theme.NoTitleBar.Fullscreen" both hides the titlebar and the notification area?
it equals to:
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
requestWindowFeature(Window.FEATURE_NO_TITLE);
I learn this from https://github.com/pocorall/scaloid-apidemos/blob/master/src/main/java/com/example/android/apis/graphics/CameraPreview.java

Related

How to remove title bar and operate in full screen mode?

I have tried to remove the title bar using the code below. But it doesnt work and it still shows the title bar.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
setContentView(R.layout.activity_main);
}
i even tried changing the theme in the mainfest file as follows.But the app stops working saying " Unfortunately myApp has stopped working".
<activity android:name="..."
android:screenOrientation="landscape"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen">
Do this before calling setContentView()
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
if (getSupportActionBar() != null)
getSupportActionBar().hide();
//Remove notification bar
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

android activity hide too bar, full screen

I would like to explain what i am doing now. I developed an aar(sdk) and is running fine. However, i would like my sdk to occupy full screen when being called, even the caller has a toolbar. i tried the sample from this link
[How to set activity to fullscreen mode in Android?
However, if i put the code in android Manifest of the sdk, my app will crashed. If i do it when sdk activity OnCreate as below code. The toolbar still there.
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_sdk_main);
May I know what do i need to do to hide the toolbar. Thanks.
If you want full screen mode for particular activity then use this
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
and for all activities Create a BaseActivity and write its onCreate method as shown above and extend this base activity for all other activities.
public void setFullScreenView() {//Hiding status/navigation bar
if (Build.VERSION.SDK_INT > 11 && Build.VERSION.SDK_INT < 19) {
View v = this.getWindow().getDecorView();
v.setSystemUiVisibility(View.GONE);
} else if (Build.VERSION.SDK_INT >= 19) {
View decorView = getWindow().getDecorView();
decorView.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);
}
setContentView(R.layout.activity_splash_screen);
}
getSupportActionBar().hide();
works.
Additional explaination, my class is an extension of AppCompatActivity, below is the code.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Logger.d(SdkMainActivity.class, "onCreate");
getSupportActionBar().hide(); //---> this works
//requestWindowFeature(Window.FEATURE_NO_TITLE); //getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN); // ---> this the toolbar still appear
setContentView(R.layout.activity_sdk_main);
}

make android app fullscreen in landscape mode only

Normally, to make my app fullscreen, inside the onCreate, before setContentView I do
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
But I have a situation where I need to enable fullscreen in landscape orientation -- but not in portrait. However, doing as below throws an exception concerning setContentView. So how do I do this correctly?
#Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if(newConfig.orientation==Configuration.ORIENTATION_PORTRAIT){
attachViewPager();
}else{
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
detachViewPager();
}
}
try this maybe it will help you
if (Build.VERSION.SDK_INT < 16) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}

android - How to Hide the stausbar

I set the following property in application tag of manifeast file. but it hides both titlebar(Actionbar) and Statusbar.Here i want to hide only the statusbar.
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
for hiding only status bar add this code in oncrete of activity:
// Hide the Status Bar
 
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
 
WindowManager.LayoutParams.FLAG_FULLSCREEN);
and remove android:theme="#android:style/Theme.NoTitleBar.Fullscreen" from manifest
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
add this code to begining of your activity
Try the following code snippet:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/* add below 2 lines*/
getWindow().clearFlags(android.view.WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
getWindow().addFlags(android.view.WindowManager.LayoutParams.FLAG_FULLSCREEN);
}

Programmatically make app FULL SCREEN in Android

I know that an app can be made full screen by tag in the manifest of the activity android:theme="#android:style/Theme.NoTitleBar.Fullscreen" Is it possible to switch to full screen mode from within the app, programmatically?
add two lines...
requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
You can create new style and add
<item name="android:windowFullscreen">true</item>
Or you can do it programmatically:
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
add this in Activity onCreate before setContentView:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// remove title
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
}
and in AndroidManifest.xml file:
<activity android:name=".ActivityName"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen">
</activity>
If you need a fullscreen immersive mode (for games, galleries, etc.), here is the solution I use and recommend.
The most efficient way is to set the SystemUIVisibility only when is needed:
In your onCreate()
With OnSystemUIChangeListener when the fullscreen mode is lost
public class BaseActivity extends Activity {
#SuppressLint("InlinedApi")
private static final int UI_OPTIONS = 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;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Step 1
hideSystemUI();
// Step 2
getWindow().getDecorView()
.setOnSystemUiVisibilityChangeListener(new View
.OnSystemUiVisibilityChangeListener() {
#Override
public void onSystemUiVisibilityChange(int visibility) {
if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
hideSystemUI();
}
}
});
}
private void hideSystemUI() {
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) actionBar.hide();
getWindow().getDecorView().setSystemUiVisibility(UI_OPTIONS);
}
}
Try this,
// remove title
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
or
<activity android:name=".ActivityName"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"/>
in onCreate() method write
requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);

Categories

Resources