截图
启动页的
activity_splash.xml
我用了一张图片自己添加吧
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout 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:id="@+id/activity_splash" tools:context=".SplashActivity" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" android:background="@mipmap/diyi"> </RelativeLayout>
manifest 定义
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.stdu"> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".SplashActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".MainActivity" /> </application> </manifest>
SplashActivity.java
package com.stdu; import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.Window; import android.view.WindowManager; import android.view.animation.AlphaAnimation; import android.view.animation.Animation; import android.widget.RelativeLayout; public class SplashActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getSupportActionBar().hide(); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);//AS下全屏隐藏标题栏代码 setContentView(R.layout.activity_splash); RelativeLayout laoutsplsh=findViewById(R.id.activity_splash); AlphaAnimation alphaAnimation =new AlphaAnimation(0.1f,1.0f); alphaAnimation.setDuration(2200); laoutsplsh.startAnimation(alphaAnimation); alphaAnimation.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { Intent intent=new Intent(SplashActivity.this,MainActivity.class); intent.setClass(getApplicationContext(),MainActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK); //把那个MainActivity设置为栈底 意思就是防止你按返回键的时候返回到哪个启动欢迎界面 startActivity(intent);//载入主窗口 } @Override public void onAnimationRepeat(Animation animation) { } }); } }
mainactivity.java
package com.stdu; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.Window; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.activity_main); } }
安卓studio 遇到的问题 ,eclipse下取消标题栏的问题再安卓studio下无法取消 ,以及点击返回按钮 会返回到启动页面的问题 例子中都已经解决
原文地址:https://www.cnblogs.com/xuexidememeda/p/9718039.html
时间: 2024-09-29 17:49:16