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

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() {
}
}

Related

How to remove the black bar appearing at the bottom?

I am new to Android Development. I want my app to support the screen size of my device i.e. 1080 x 2160 pixels. Currently there is a black bottom bar that is displayed in place of where the navigation buttons would have been.
Please note that I do not want Full Screen Mode. I have disabled the button navigation on my device. It is only for this app that that the bottom black rectangle is showing.
I just want my app to support the gesture navigation system of my device instead of buttons.How do I make the bottom bar go away using Java (Android Studio) so that my app utilizes that space?
question is old but I faced the same issue and didnot find the solution on SO.
this problem occurs for long screens
We recommend that you design your app to support aspect ratios of 2.1 or higher. For this, you would add the following to the "application" element in your Manifest file:
<meta-data android:name="android.max_aspect" android:value="2.1" />
from here
I had the same issue, updated manifest file with this or remove if you have one.
before
<meta-data
android:name="android.max_aspect"
android:value="2.1" />
after
<meta-data
android:name="android.max_aspect"
android:value="2.4" />
working for me now.
Hi please Try below code
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
You can try this
#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);
}
}
Try to add this code
#Override
protected void onCreate(Bundle savedInstanceState) {
...
hideSystemUI(this, 1000);
}
#Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (hasFocus) {
// Hide bar after 1 second
hideSystemUI(this, 1000);
}
}
public static void hideSystemUI(#NonNull final Activity activity, final int delayMs) {
View decorView = activity.getWindow().getDecorView();
int uiState = View.SYSTEM_UI_FLAG_IMMERSIVE
| 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;
final Handler handler = new Handler();
decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {
#Override
public void onSystemUiVisibilityChange(int visibility) {
if (visibility == View.VISIBLE) {
Runnable runnable = new Runnable() {
#Override
public void run() {
hideSystemUI(activity, 1000);
}
};
handler.postDelayed(runnable, delayMs);
}
}
});
decorView.setSystemUiVisibility(uiState);
}
WARNING
If you have two activities, add this before changing
View decorView = getWindow().getDecorView();
decorView.setOnSystemUiVisibilityChangeListener(null);

setOnSystemUiVisibilityChangeListener only works in main activity for hidding navigation bar

I want to hide the navigation bar in my Android application. I have written the following class:
import android.view.View;
public class NavigationUtils {
private NavigationUtils() {
}
public static void hideNavigation(View decorView) {
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 call this method in the onResume() method, the navigation bar is hidden. In addition in the onCreate() method of my main activity I'm using the following piece of code:
View decorView = getWindow().getDecorView();
decorView.setOnSystemUiVisibilityChangeListener
(new View.OnSystemUiVisibilityChangeListener() {
#Override
public void onSystemUiVisibilityChange(int visibility) {
if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
NavigationUtils.hideNavigation(getWindow().getDecorView());
}
}
}
);
When I click on an EditText the soft keyboard opens as well as the navigation bar. With the above code the navigation bar is again hidden when the soft keyboard is closed. This works nicely in the main activity.
Now I have started another activity from the main activity and I have added the same piece of code in the onCreate() method as above.
But now when I exit the soft keyboard (after editing an EditText) in the new activity the navigation bar is no more hidden.
What can I do?
Edit: The entries in the manifest for the two activities are the following:
<activity
android:name=".MainActivity"
android:configChanges="orientation"
android:screenOrientation="landscape">
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".SensorReadingsActivity"
android:screenOrientation="landscape" />

how to keep full screen when keyboard popup

I am working on my full-screen project recently, and it's implemented by Immersive mode. It works fine and correctly except one part:
As keyboard popping up, hiding status bar will also shows up.
How can I get rid of it? I want status bar keep hiding when I click edittext in my layout.
here's my code:
int flag = View.SYSTEM_UI_FLAG_LOW_PROFILE
|View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
|View.SYSTEM_UI_FLAG_LAYOUT_STABLE
|View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|View.SYSTEM_UI_FLAG_FULLSCREEN
|View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
|View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mDecorView = activity.getWindow().getDecorView();
mDecorView.setSystemUiVisibility(flag);
mDecorView.setOnSystemUiVisibilityChangeListener(
new View.OnSystemUiVisibilityChangeListener() {
#Override
public void onSystemUiVisibilityChange(int visibility) {
if ((visibility & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0) {
mDecorView.setSystemUiVisibility(flag);
}
}
});
}
#Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if ((visibility & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0) {
mDecorView.setSystemUiVisibility(flag);
}
}
It must have some walk-around solution. I've seen that some app hide status bar well even when keyboard popup.
Any ideas how to solve this?
you must use <ScrollView> as main layout. example:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
....
</ScrollView>
or use this code in AndroidManiFest.xml:
<activity
android:windowSoftInputMode="adjustNothing">
</activity>

Android : Buttons in the background Activity of a 'Dialog' is active?

I have an Activity which has an 'OK' button. And I have an 'Edit' button which will open a Dialog (theme="#android:style/Theme.Holo.Light.Dialog"). When I am in the EditDialog, I can see the OK button in the background Activity, and I can press that, and it the press is getting registered.
Is there a way to disable the background Activity actions when a Dialog is open? i.e. I want to modify things in the Dialog alone.
Edit: Adding a sample code which shows this behaviour.
Main Activity:
public class DialogTestActivity extends Activity implements OnClickListener {
private final String TAG = "DialogTest.main";
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
((Button) findViewById(R.id.button_open)).setOnClickListener(this);
((Button) findViewById(R.id.button_ok)).setOnClickListener(this);
}
public void onClick(View v) {
switch (v.getId()) {
case R.id.button_ok:
Log.w(TAG, "OK Button Pressed!");
break;
case R.id.button_open:
Log.d(TAG, "Opening new Window.");
Intent intent = new Intent(this, TestDialog.class);
startActivity(intent);
default:
break;
}
}
}
TestDialog 'dialog':
public class TestDialog extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.test_dialog);
LayoutParams params = getWindow().getAttributes();
params.height = LayoutParams.WRAP_CONTENT;
Window window = this.getWindow();
window.setAttributes((android.view.WindowManager.LayoutParams) params);
window.setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
}
}
Manifest:
<activity
android:name=".DialogTestActivity"
android:label="#string/app_name"
android:theme="#android:style/Theme.Holo.Light" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".TestDialog"
android:label="#string/dialog_label"
android:theme="#android:style/Theme.Holo.Light.Dialog" >
</activity>
With the above code, when the TestDialog was open, the Button Press on the background Activity were registered - OK Button Pressed! will be logged.
First, this is not a dialog. This is a dialog-themed activity. A dialog inherits from Dialog.
Second, your use of WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL is giving you precisely the behavior that you do not want. Delete this line of code, and things should work better.
Nothing in the underlying Activity should be clickable when a Dialog is in the foreground (this is how Dialogs in Android work). If you are able to interact with the underlying Activity when the Dialog is open, then there is probably something wrong with your implementation.
Edit:
Remove this line and all should work:
this.setCanceledOnTouchOutside(false);
If your Activity is opened with set Dialog theme use code below
setFinishOnTouchOutside(false);

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