I want to make a splash screen in my application, for that i need to know how to show an image in full screen. This could me made by XML or Java code ? And how?
For now i just made this:
public class SplashScreen extends Activity {
private static final int STOPSPLASH = 0;
private static final long SPLASHTIME = 5000;
private Handler splashHandler = new Handler() {
#Override
public void handleMessage(Message msg) {
switch (msg.what) {
case STOPSPLASH:
//remove SplashScreen from view
Intent intent = new Intent(SplashScreen.this, jetpack.class);
startActivity(intent);
break;
}
super.handleMessage(msg);
}
};
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash_screen);
Message msg = new Message();
msg.what = STOPSPLASH;
splashHandler.sendMessageDelayed(msg, SPLASHTIME);
}
}
How can be this splash_screen.xml ?
Thank you for your help.
The best way to show a full screen splash activity is by putting this line in your manifest under activity tag
android:theme="#android:style/Theme.Light.NoTitleBar.Fullscreen"
You can use other themes as well
Theme.Black.NoTitleBar.Fullscreen
Theme.NoTitleBar.Fullscreen
<activity
android:name="com.example.SplashActivity"
android:label="#string/app_name"
android:theme="#android:style/Theme.Light.NoTitleBar.Fullscreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
For Latest Api Lollipop and above
<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>
</style>
Define this theme for the splash activity and provide it in manifest
android:theme="#style/Theme.AppCompat.Light.NoActionBar.FullScreen"
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="#drawable/image" />
</LinearLayout>
and add the below code before setContentView(R.layout.splash_screen);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
If R.layout.splash_screen included an image with height and width set to fill_parent or match_parent (depending on version). It will fill the screen
<style name="FullScreen" parent="Theme.AppCompat.Light.NoActionBar">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">#null</item>
</style>
just using super.onCreate and setConntentView
code :
/** Hiding Title bar of this activity screen */
getWindow().requestFeature(Window.FEATURE_NO_TITLE);
/** Making this activity, full screen */
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_splash);
Related
Trying to create simple application with fullscreen video playing.
Navigation bar hides, but activity is not filling the screen.
What am I missing?
activity:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="my.test.app2.VViewer">
<VideoView
android:id="#+id/videoView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout >
public class VViewer extends AppCompatActivity {
private VideoView myVideo;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_vviewer);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
|View.SYSTEM_UI_FLAG_FULLSCREEN
|View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
);
}
#Override
protected void onResume ()
{
super.onResume();
myVideo=(VideoView)findViewById(R.id.videoView);
myVideo.setVideoPath(MP4FileName);
myVideo.start();
}
theme for activity
<style name="AppTheme.FullscreenTheme" parent="#style/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:windowContentOverlay">#null</item>
</style>
you can try this :
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
My code works fine for 16:9 screen devices. Problems only on 18:9 devices.
I don't understand why, but adding
<meta-data android:name="android.max_aspect" android:value="2.1" />
to application section of android manifest file solves the problem.
I have created a splash screen with code,
Activity:
public class Splash extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new MyView(Splash.this));
}
public class MyView extends View {
Bitmap splashBmp;
public MyView(Context context) {
super(context);
}
#Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
try {
int x = getHeight();
int y = getWidth();
Paint paint = new Paint();
paint.setStyle(Paint.Style.FILL);
paint.setColor(Color.WHITE);
canvas.drawPaint(paint);
splashBmp = BitmapFactory.decodeResource(getResources(), R.drawable.splash);
splashBmp = Bitmap.createScaledBitmap(splashBmp, (y),(x), true);
canvas.drawBitmap(splashBmp,0, 0, paint);
} catch (Exception e) {}
}
}
}
<style name="splash" 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:windowContentOverlay">#null</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowDisablePreview">false</item>
</style>
AndroidManifest file:
<activity
android:name=".Splash"
android:noHistory="true"
android:theme="#style/splash">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
The problem is app always takes 3 or 4 seconds to launch splash screen(without white screen) after the launcher icon click. How to solve this??
I have tried both xml and Canvas.
Here is most robust way to start splash with 0 second delay.
You have to set an theme only to your splash activity. You will set an
background instead of using layout on Splash Screen.
<activity
android:name=".SplashActivity"
android:theme="#style/SplashTheme">
...
</activity>
Put this style in your styles.xml
<style name="SplashTheme" parent="AppTheme.NoActionBar">
<item name="android:windowBackground">#drawable/splash_bitmap</item>
</style>
Here splash_bitmap can be any drawable png, jpg, or xml drawable.
Here is mine you can make yours inside res>drawable directory.
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#color/colorPrimary" />
<item>
<bitmap
android:gravity="center"
android:src="#drawable/ic_launcher" />
</item>
</layer-list>
I am implementing searchview in my app. When I click on search new activity is opened to show results but the color of status bar changes in new activity. Here is my code:
activity_search.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/coordinator_layout">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/search_results_recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
</android.support.v7.widget.RecyclerView>
</android.support.design.widget.CoordinatorLayout>
SearchResultActiviy.java
public class SearchResultActivity extends AppCompatActivity{
private Toolbar toolbar;
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_search);
toolbar = (Toolbar) findViewById(R.id.toolbar);
handleIntent(getIntent());
}
}
#Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
handleIntent(getIntent());
}
private void handleIntent(Intent intent) {
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
query = intent.getStringExtra(SearchManager.QUERY);
getPatientList(startRow,pageSize);
}
}
AndroidManifest.xml
<activity android:name=".activities.SearchResultActivity"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.SEARCH"/>
</intent-filter>
<meta-data
android:name="android.app.searchable"
android:resource="#xml/searchable" />
</activity>
Style.xml
<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>
<item name="android:statusBarColor">#android:color/transparent</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:textAllCaps">false</item>
</style>
here are the images
In your Style.xml, you define the statusBarColor to transparent.
This parameter need API level 21.
I recommend deleting the line :
<item name="android:statusBarColor">#android:color/transparent</item>
The color of status bar is set by ColorPrimaryDark (see https://developer.android.com/training/material/theme.html)
If you want to change the color dynamically, use
Window window = activity.getWindow();
// clear FLAG_TRANSLUCENT_STATUS flag:
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
// add FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS flag to the window
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
// finally change the color
window.setStatusBarColor(activity.getResources().getColor(R.color.my_statusbar_color));
Explain in this thread : statusBar
(It's my first answer, hope it helps)
I have the code as below in my Android app.
My res/values/styles.xml:
<style name="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:windowBackground">#drawable/background_splash</item>
</style>
res/drawable/background_splash.xml:
<item
android:drawable="#color/colorPrimaryDark"/>
<item>
<bitmap
android:gravity="center"
android:src="#mipmap/image1"/>
</item>
AndroidManifest.xml:
<activity
android:name=".SplashActivity"
android:theme="#style/FullScreen">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
SplashActivity.java:
public class SplashActivity extends AppCompatActivity {
private static int SPLASH_TIME_OUT = 5000;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.activity_splash);
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
Intent i = new Intent(SplashActivity.this, MainActivity.class);
startActivity(i);
finish();
}
}, SPLASH_TIME_OUT);
}
}
I have the image1 with appropriate resolution/size present in the res folder. But the splash screen does not display the image covering full screen but displays with reduced size only some part of the screen. Can you please advice what needs to be done. I went through some of the suggestions present on some sites but it did not help.
In your res/drawable/background_splash.xml, change android:gravity
you can use fill, in my case I used top|fill_horizontal for horizontal fill only, choose the combination you want.
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#color/White"/>
<item>
<bitmap
android:gravity="top|fill_horizontal"
android:src="#drawable/splash"/>
</item>
</layer-list>
use parent of theme
parent="#style/Theme.AppCompat.Light.NoTitleBar.Fullscreen"
code for activity_splash.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
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:background="#color/colorAccent"
tools:context=".SplashActivity">
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="#drawable/icon"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
/>
</android.support.constraint.ConstraintLayout>
Code for Splash.java
import android.content.Intent;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class SplashActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportActionBar().hide();
setContentView(R.layout.activity_splash);
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
#Override
public void run() {
Intent i = new Intent(SplashActivity.this,MainActivity.class);
startActivity(i);
finish();
}
},2000);
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="#drawable/image" />
</LinearLayout
And use
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
in your Activity code.
Make sure your splash xml file has no padding of any sort. If any, delete.
Im showing a popup alert activity, when select a notification from tray.
But on top it's showing the App name (MCP), with improper alignment.
I don't want the top part, just a normal dialog.
Manifest:
<activity
android:name=".activity.AlertDialogActivity"
android:configChanges="orientation|locale|screenSize|uiMode|fontScale"
android:excludeFromRecents="true"
android:theme="#style/AlertDialogTheme" />
Style:
<style name="AlertDialogTheme" parent="Theme.AppCompat.Dialog">
<item name="android:windowNoTitle">true</item>
</style>
Alert activity:
public class AlertDialogActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_alert_dialog);
this.setFinishOnTouchOutside(false);
String message = getIntent().getExtras().getString("message");
TextView tvPushMessage = (TextView) findViewById(R.id.tvAlertMessage);
tvPushMessage.setText(message);
Button btnPushOk = (Button) findViewById(R.id.btnAlertOk);
btnPushOk.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
finish();
}
});
}
Layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:background="#drawable/background_round_rectangle"
android:padding="#dimen/activity_vertical_margin">
<TextView
android:id="#+id/tvAlertMessage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:text="Message"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/black" />;
<Button
android:id="#+id/btnAlertOk"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_below="#id/tvAlertMessage"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:background="#drawable/btn_use"
android:text="#string/ok"
android:textColor="#color/white" />
</RelativeLayout>`
Also tried:
requestWindowFeature(Window.FEATURE_NO_TITLE);
and:
getWindow().setFeatureDrawableResource(Window.FEATURE_NO_TITLE, android.R.drawable.ic_dialog_alert)
before setContentView()
Just Add Following code in style.xml
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
or You can hide it Programmatically.
getSupportActionBar().hide();
Try this code (without using "android:")
<style name="Theme.MyDialog" parent="#style/Theme.AppCompat.Dialog">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
I used this:
In AppCompatActivity onCreate() add following codeļ¼
setTitle("")
and Add The following code in style.xml
<style name="PopupWindowTheme" parent="#style/Theme.AppCompat.Dialog.Alert">
<item name="android:windowBackground">#color/transparent</item>
<item name="android:windowIsTranslucent">false</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowAnimationStyle">#style/AnimBottom</item>
</style>
Add requestWindowFeature in this way may be work proper.
First Call Super after add it.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.add__favourite_layout);
}