Splash screen still exist in next activity android - java

I created a splash screen due to this tutorial: Splash Screen right way
But I have a problem that the splash screen always on display when I create new activity
It just cover the whole activity layout, is there anyway to remove it? I'm new to Android. I dont know how to search this problem on Google. Please help.

IMO, this is the best tutorial for splash screens
create a drawable background_splash
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="#color/gray"/>
<item>
<bitmap
android:gravity="center"
android:src="#mipmap/ic_launcher"/>
</item>
add theme
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">#drawable/background_splash</item>
</style>
add to you manifiest
<activity
android:name=".SplashActivity"
android:theme="#style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
add splash activity that forwards to your main activity
public class SplashActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
finish();
}
}

I think you should replace your main application with splash theme. So Please separate your main application theme and your splash theme.
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
// Splash Theme
<style name="SplashTheme" parent="AppTheme">
<item name="android:windowBackground">#drawable/splash</item>
</style>
Change Theme in XML

Related

Android splash screen jump java

I wanted to implement a splash screen but in a correct way - no superficial delay, only showing it while the app is doing some real work. So I googled a lot and found following solution: I apply theme to SplashActivity, procced with the logic and open next activity. The problem is that splash screen jumps a little bit. Tried different options - fullscreen, no action bar for splash, no action bar for splash and following activity, android:windowDrawsSystemBarBackgrounds true\false and several others. If I set delay for 115-150 millisecs then 9 cases out of 10 there is no jump. The question is how to get rid of the jump and keep splash screen lean.
SplashActivity:
public class SplashActivity extends CheckForInternetActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
routeActivity();
}
AndroidManifest:
<activity
android:name="ru.awac.CBoRrates.SplashActivity"
android:screenOrientation="portrait"
tools:ignore="LockedOrientationActivity"
android:theme="#style/AppTheme.SplashScreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
styles.xml:
<style name="AppTheme.SplashScreen" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowBackground">#drawable/splash_screen</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
splash_screen:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
android:opacity="opaque">
<item android:drawable="#android:color/white"/>
<item>
<bitmap
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
android:layout_margin="5dip"
android:src="#drawable/awac_presents_transparent_1" />
</item>
</layer-list>
awac_presents_transparent_1 is just a png
Youtube video of the jump

open activity from another activity after some seconds

I try to open a new activity from another one after some seconds, I used this code,
but it's not working (first activity runs but after some seconds I have an error)
public class WelcomeActivity extends AppCompatActivity {
private static int TIME_OUT = 4000;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_welcome);
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
Intent intent = new Intent(WelcomeActivity.this, MainActivity.class);
startActivity(intent);
//finish();
}
}, TIME_OUT);
}
}
This is a stacktrace:
java.lang.RuntimeException: Unable to start activity
ComponentInfo{________}: java.lang.IllegalStateException: This
Activity already has an action bar supplied by the window decor. Do
not request Window.FEATURE_SUPPORT_ACTION_BAR and set windowActionBar
to false in your theme to use a Toolbar instead
The problem is not with this code. According to your exception the problem is in the MainActivity class. I think your are trying to create custom action bar. But the error is occurring due to your current theme already have an action bar. So you need customize your theme for that class.
In styles.xml create a new theme.
<style name="Theme.FullScreen" parent="AppTheme.NoActionBar">
<item name="android:windowNoTitle">false</item>
<item name="android:windowFullscreen">false</item>
<item name="android:windowActionBar">false</item>
</style>
In the AndroidManifest.xml change the theme of your view to your customized theme.
<activity
android:name=".MainActivity "
android:theme="#style/Theme.FullScreen" />
This link will help you.
make
<item name="windowActionBar">false</item> in your style.xml
Example:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- 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:windowAnimationStyle">#style/AnimationActivity</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

Basic toolbar crashes app

I created a basic tool bar off the android website and it is crashing with a code it gives to put in the onCreate Section. the only widget in the program so far is that and it crashed with the .java code
home.java
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.os.Bundle;
public class Home extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
Toolbar my_toolbar = (Toolbar) findViewById(R.id.my_toolbar);
setSupportActionBar(my_toolbar);
}
}
xml
<android.support.v7.widget.Toolbar
android:id="#+id/my_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:elevation="4dp"
android:theme="#style/ThemeOverlay.AppCompat.ActionBar"
android:popupTheme="#style/ThemeOverlay.AppCompat.Light"/>
Make sure the theme of your activity Home does not have an ActionBar already. Check the manifest file to find out which theme is being used.
Also check the file styles.xml and make sure the the theme used by your activity does not have an ActionBar. Use something like this:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
In your styles.xml put below code..
<!-- Base application theme. -->
<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>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
and in your AndroidManifest.xml write the theme as below
<activity android:name=".Home"
android:theme="#style/AppTheme.NoActionBar"></activity>

You need to use a Theme.AppCompat theme error, even with theme set to AppCompat

I am busy trying to implement The support library so that i can make use of AppCompatActivty
As far as I know I have everything in the correct place. But I am still getting the error.
styles.xml
<resources>
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
</resources>
v21/styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppBaseTheme" parent="Theme.AppCompat.Light"></style>
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
</resources>
manifest.xml
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher_on"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
activity.java
public class RegisterActivity extends AppCompatActivity
Now when I run my application and try open RegisterActivty I get the following error.
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.tuta_me/activities.RegisterActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
I must have missed something somewhere. What am I doing wrong?
Add this
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
</style>
in your v21/styles.xml file. Without it, <style name="AppTheme" parent="AppBaseTheme"> has no meaning.
Look at this, maybe helps: https://stackoverflow.com/a/53749686/6883143
This answer looks like:
I have same problem when I've migrate to androidx. I've solve this by simply updating from
implementation 'androidx.appcompat:appcompat:1.0.0'
to
implementation 'androidx.appcompat:appcompat:1.0.2'

android - can't customize ActionBar

Somehow I'm having a difficult time figuring out a seemingly easy problem. None of the attributes I specify, including android:text, android:textSize, android:textColor, android:textAppearance, seem to do anything to my ActionBar. When I run my project "MainActivity" on the ActionBar is still white and the default font size. I'm using API level 16.
Here's my styles.xml:
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="AppTheme" parent="android:style/Theme.Holo">
<item name="android:actionBarStyle">#style/ActionBar</item>
</style>
<style name="ActionBar" parent="android:style/Widget.Holo.ActionBar">
<item name="android:text">This String Is Not Showing Up In ActionBar!</item>
<item name="android:textColor">#android:color/holo_orange_dark</item>
<item name="android:textSize">44dp</item>
</style>
</resources>
and my AndroidManifest.xml:
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Can someone please tell me what I'm doing wrong?
A few things:
<item name="android:text">This String Is Not Showing Up In ActionBar!</item>
This won't work. The actionbar title should be set using the activities label field in your manifest or by accessing the actionbar object in your activity.
UPDATE: the struck out information was partially inaccurate. Turns out you can set the title of the actionbar in styles.xml with the android:title tag. Here is a more accurate solution:
<style name="ActionBar" parent="android:style/Widget.Holo.ActionBar">
<item name="android:title">This String WILL show up in the ActionBar!</item>
<item name="android:textColor">#android:color/holo_orange_dark</item>
<item name="android:textSize">44dp</item>
</style>
OLD ANSWER:
To change the text style of the actionbar title (titleTextStyle) you will need a new style:
<style name="Text.ActionBar">
<item name="android:textColor">#android:color/holo_orange_dark</item>
<item name="android:textSize">44dp</item>
</style>
and reference it from your actionbar style
<style name="ActionBar" parent="android:style/Widget.Holo.ActionBar">
<item name="android:titleTextStyle">#style/Text.ActionBar</item>
</style>
For more information on the styles you can theme in the actionbar check out the R.attr documentation.
I was able to do similar things with the below code. PS - I used Appcompat but since you are using ApI 16 you can use the current ActionBar itself.
<!-- general styles for the action bar -->
<style name="MyActionBar" parent="#style/Widget.AppCompat.ActionBar">
<item name="android:titleTextStyle">#style/TitleTextStyle</item>
<item name="android:background">#drawable/actionbar_background</item>
</style>
<!-- action bar title text -->
<style name="TitleTextStyle" parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#color/actionbar_text</item>
<item name="android:textSize">100sp</item>
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppCompatTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>

Categories