如何在启动画面活动后打开fragement活动 [英] How to open fragement activity on after splash screen activity
问题描述
Hello Guys,我想知道如何在启动画面活动后打开片段活动,在启动画面中我在启动画面中使用动画请帮助我如何打开它。
提前致谢。
我的尝试:
< pre lang =java> package com.complainprotectioncell;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
public class SplashScreen extends AppCompatActivity {
public MediaPlayer mp;
@ Override
protected void onCreate(Bundle savedInstanceState){
super .onCreate(savedInstanceState);
尝试 {
// getSupportActionBar()。hide();
// requestWindowFeature(Window.FEATURE_NO_TITLE);
// getWindow()。setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
// WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout。 front_splash_screen);
mp = MediaPlayer.create( this ,R.raw.bgr_be_happy);
mp.start();
startAnimation();
} catch (例外情况)
{
Log.e( 异常, 找到1 + ex);
}
}
public void startAnimation( )
{
尝试 {
final ImageView imageView =(ImageView )findViewById(R.id.imageView);
final 动画animation_1 = AnimationUtils.loadAnimation(getBaseContext(),R.anim.rotate);
final 动画animation_2 = AnimationUtils.loadAnimation(getBaseContext(),R.anim.antirotate);
final 动画animation_3 = AnimationUtils.loadAnimation(getBaseContext(),R.anim.abc_fade_out);
imageView.startAnimation(animation_2);
animation_2.setAnimationListener( new Animation.AnimationListener(){
@ Override
public void onAnimationStart(动画动画){
}
@覆盖
public void onAnimationEnd(动画动画){
imageView.startAnimation(animation_1);
}
@ Override
public void onAnimationRepeat(动画动画){
}
});
animation_1.setAnimationListener( new Animation.AnimationListener(){
@ Override
public void onAnimationStart(动画动画){
}
@覆盖
public void onAnimationEnd(动画动画){
尝试 {
startActivity( new Intent(getApplicationContext(),Login。 class ));
finish();
// imageView.startAnimation(animation_3);
// mp.release();
} catch (Exception ex){
Log.e( Exception Splash,ex + );
// Toast.makeText(SplashScreen.this,抱歉,事情变得错了,Toast.LENGTH_SHORT) .show();
}
}
@覆盖
public void onAnimationRepeat(动画动画){
}
});
} catch (例外情况)
{
Log.e( 异常, 找到2);
}
}
@覆盖
protected void onStop(){
super .onStop();
尝试 {
if (mp!= null&& mp。 isPlaying()){
mp.stop();
mp.release();
mp = null;
}
} catch (例外情况)
{
Log.e( 发现异常,ex + 跨度>);
}
}
} 我采用了一种与众不同的方法我的一个应用程序,因为它应该立即就绪,甚至在布局膨胀之前。因此,我没有使用布局,而是将启动画面的背景指定为活动的主题背景。
因此,我在 AndroidManifest.xml中将主要活动更改为
文件,如: SplashActivity
< activity
android:name =。MainActivity
android:label =@ string / app_name
android:theme =@ style / AppTheme.NoActionBar>
< / activity>
< 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>
< / activity>
SplashActivity
的背景/主题如下:
< style name =SplashThemeparent =Theme.AppCompat.NoActionBar>
< item name =android:windowBackground> @ drawable / background_splash< / item>
< / style>
...
<?xml version =1.0encoding =utf-8?>
< layer-list xmlns:android =http://schemas.android.com/apk/res/android>
< item android:drawable =@ color / grey/>
< item>
< bitmap android:gravity =centerandroid:src =@ mipmap / ic_launcher/>
< / item>
< / layer-list>
SplashActivity
类看起来像:
公共类SplashActivity扩展AppCompatActivity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
Intent intent = new Intent(this,MainActivity.class);
startActivity(intent);
完成();
}
}
然后在 MainActivity
中,按照您的意愿做任何事情。可能不是你想要的,但这也是谷歌现在这样做的方式。
Hello Guys, I want to know how can I open my fragment activity after splash screen activity and in my splash screen I am using animation in my splash screen please help me how can I open it.
Thanks in Advance.
What I have tried:
package com.complainprotectioncell;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
public class SplashScreen extends AppCompatActivity {
public MediaPlayer mp;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try {
// getSupportActionBar().hide();
// requestWindowFeature(Window.FEATURE_NO_TITLE);
// getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
// WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.front_splash_screen);
mp = MediaPlayer.create(this, R.raw.bgr_be_happy);
mp.start();
startAnimation();
}catch(Exception ex)
{
Log.e("Exception" , "Found 1" + ex);
}
}
public void startAnimation()
{
try {
final ImageView imageView = (ImageView) findViewById(R.id.imageView);
final Animation animation_1 = AnimationUtils.loadAnimation(getBaseContext(), R.anim.rotate);
final Animation animation_2 = AnimationUtils.loadAnimation(getBaseContext(), R.anim.antirotate);
final Animation animation_3 = AnimationUtils.loadAnimation(getBaseContext(), R.anim.abc_fade_out);
imageView.startAnimation(animation_2);
animation_2.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
imageView.startAnimation(animation_1);
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
animation_1.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
try {
startActivity(new Intent(getApplicationContext(), Login.class));
finish();
//imageView.startAnimation(animation_3);
//mp.release();
} catch (Exception ex) {
Log.e("Exception Splash", ex + "");
// Toast.makeText(SplashScreen.this, "Sorry, Something went Wrong", Toast.LENGTH_SHORT).show();
}
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
}catch(Exception ex)
{
Log.e("Exception" , "Found 2");
}
}
@Override
protected void onStop() {
super.onStop();
try {
if (mp != null && mp.isPlaying()) {
mp.stop();
mp.release();
mp = null;
}
}catch(Exception ex)
{
Log.e("Exception Found", ex + "");
}
}
}
I took a far different approach with a splash screen for one of my apps because it should be ready immediately, even before a layout is inflated. So instead of using a layout, I specified the splash screen's background as the activity's theme background.
So, I changed the main activity to beSplashActivity
in theAndroidManifest.xml
file, like:
<activity android:name=".MainActivity" android:label="@string/app_name" android:theme="@style/AppTheme.NoActionBar"> </activity> <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> </activity>The background/theme for the
SplashActivity
looks like:
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar"> <item name="android:windowBackground">@drawable/background_splash</item> </style> ... <?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> </layer-list>The
SplashActivity
class then looks like:
public class SplashActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Intent intent = new Intent(this, MainActivity.class); startActivity(intent); finish(); } }Then in
MainActivity
, do whatever you want as normal. May not be exactly what you are looking for, but it is the way Google is doing this now, too.
这篇关于如何在启动画面活动后打开fragement活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!