Programmatically make app FULL SCREEN in Android - 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);

Related

Detect soft-keyboard hide and hide the navigation buttons

I'm new to Java and Android, so the code i have i pasted together from the net. The goal is to create a simple web browser for one webpage. In that webpage, it's possible to edit text and such.
Main goal is to keep the browser full screen, so to keep away the android navigation buttons.
I tried to use this code but no success until know.
Detecting Soft Keyboard Hidden State
public class MainActivity extends AppCompatActivity {
private static final String TAG = "MyActivity";
static int mAppHeight;
static int currentOrientation = -1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE); //will hide the title
getSupportActionBar().hide(); // hide the title bar
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN); //enable full screen
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION|
View.SYSTEM_UI_FLAG_IMMERSIVE);
setContentView(R.layout.activity_main);
//make a webview object
WebView webview=new WebView(this);
webview.setWebViewClient(new WebViewClient() {
#Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION|
View.SYSTEM_UI_FLAG_IMMERSIVE);
}
});
// enable javascript
WebSettings webSettings = webview.getSettings();
webSettings.setJavaScriptEnabled(true);
//show it through setcontentview()method
setContentView(webview);
webview.loadUrl("https://www.mypage.com");
}
#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_HIDE_NAVIGATION |
View.SYSTEM_UI_FLAG_IMMERSIVE);
}
}
Can someone help where to put the code from the link?
Thank you very much
Kind regards
EDIT:
I also tried this one, but i don't see the event get run when the soft keyboard shows or hides.: https://github.com/yshrsmz/KeyboardVisibilityEvent
Try:
View decorView = getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
In your manifest use this -
<activity
android:name=".Activities. MainActivity"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.Light.NoTitleBar.Fullscreen">
</activity>
In Activity onCreate use only this -
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout. activity_main);
AND REMOVE
requestWindowFeature(Window.FEATURE_NO_TITLE); //will hide the title
getSupportActionBar().hide(); // hide the title bar
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN); //enable full screen
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION|
View.SYSTEM_UI_FLAG_IMMERSIVE);
setContentView(R.layout.activity_main);

How to make splash screen image visible in navigation bar also?

I have an image which I want to place in splash screen in such a way that it is visible in navigation bar also at the top. Normally the image is visible in full activity except the navigation bar. But I want it to start from navigation bar also as in swiggy app splash screen.
Below is the related image:
Try this add to the manifest the theme of the first activity to exclude the action bar, and maybe even the notification bar?
Method 1
<application
android:allowBackup="true"
android:icon="#drawable/lojacidadao"
android:label="#string/app_name"
android:theme="#style/AppTheme">
<activity
android:name="com.example.basicmaponline.Intro"
android:screenOrientation="portrait"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Method 2
Another way is, do this through code in the activity. In your activity do the following before calling setContentView() function
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);
the reason you have the action bar is because you have set the default theme to have it, in the application tag, so it's not an activity before yours, it's really your own splash activity.
In your splash screen activity theme in styles.xml add
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
maybe if you set activity theme none(default in manifest) and set image fill_parent, the screen is displayed like that.
Try this:
public class SplashActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setFullScreenView();
}
public void setFullScreenView() {
if (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); // set your view here
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
startActivity(MainActivity.class);
}
}, 2500);
}
/**
* #param cls ClassName.class to start new Activity
*/
private void startActivity(Class<?> cls) {
Intent intent = new Intent(SplashActivity.this, cls);
startActivity(intent);
finish();
}
#Override
public void onBackPressed() {
}
}

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

Android Fullscreen Not Working: Gingerbread

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

Categories

Resources