<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=".MainActivity"> </activity> <activity android:name=".SplashActivity" android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".GuideActivity"></activity> </application>
/** * Created by wt on 2017/11/20. */ public class GuideActivity extends AppCompatActivity { private Button button; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_guide); button=(Button)findViewById(R.id.button); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { PrefUtils.putBoolean("is_show",true,GuideActivity.this); startActivity(new Intent(GuideActivity.this,MainActivity.class)); finish(); } }); } }
/** * Created by wt on 2017/11/20. */ public class SplashActivity extends Activity { @Bind(R.id.splash_layout) RelativeLayout splashLayout; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.splash_layout); ButterKnife.bind(this); //旋轉 縮放 漸變 init(); } private void init() { /** * 旋轉 * 從0到360度旋轉 樣式Animation.RELATIVE_TO_SELF居於自身旋轉,從0.5的位置旋轉 */ RotateAnimation rotateAnim=new RotateAnimation(0,360, Animation.RELATIVE_TO_SELF,0.5f, Animation.RELATIVE_TO_SELF,0.5f); /** * 時間爲1s鍾 */ rotateAnim.setDuration(1000); //保持狀態 rotateAnim.setFillAfter(true); /** * 縮放 * x 0,1從無到有 y 0,1從無到有 樣式x 0.5 y 0.5 從中心縮放 */ ScaleAnimation scaleAnim=new ScaleAnimation(0,1,0,1,Animation.RELATIVE_TO_SELF,0.5f, Animation.RELATIVE_TO_SELF,0.5f); scaleAnim.setDuration(1000); scaleAnim.setFillAfter(true); /** * 漸變 * */ AlphaAnimation alphaAnim=new AlphaAnimation(0,1); alphaAnim.setDuration(2000); alphaAnim.setFillAfter(true); /** * 動畫集合 */ AnimationSet animation=new AnimationSet(true); animation.addAnimation(alphaAnim); animation.addAnimation(scaleAnim); // animation.addAnimation(rotateAnim); splashLayout.startAnimation(animation); animation.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { //判斷是否第一次登錄 boolean isShow= PrefUtils.getBoolean("is_show",false,SplashActivity.this); if (isShow) { startActivity(new Intent(SplashActivity.this,MainActivity.class)); finish(); }else { //跳轉到引導頁 startActivity(new Intent(SplashActivity.this,GuideActivity.class)); finish(); } } @Override public void onAnimationRepeat(Animation animation) { } }); } }
//工具類
/** * Created by wt on 2017/11/20. */ public class PrefUtils { public static void putBoolean(String key, boolean value, Context ctx) { SharedPreferences sp = ctx.getSharedPreferences("config", Context.MODE_PRIVATE); sp.edit().putBoolean(key, value).commit(); } public static boolean getBoolean(String key, boolean defValue, Context ctx) { SharedPreferences sp = ctx.getSharedPreferences("config", Context.MODE_PRIVATE); return sp.getBoolean(key, defValue); } public static void putString(String key, String value, Context ctx) { SharedPreferences sp = ctx.getSharedPreferences("config", Context.MODE_PRIVATE); sp.edit().putString(key, value).commit(); } public static String getString(String key, String defValue, Context ctx) { SharedPreferences sp = ctx.getSharedPreferences("config", Context.MODE_PRIVATE); return sp.getString(key, defValue); } public static void putInt(String key, int value, Context ctx) { SharedPreferences sp = ctx.getSharedPreferences("config", Context.MODE_PRIVATE); sp.edit().putInt(key, value).commit(); } public static int getInt(String key, int defValue, Context ctx) { SharedPreferences sp = ctx.getSharedPreferences("config", Context.MODE_PRIVATE); return sp.getInt(key, defValue); } public static void remove(String key, Context ctx) { SharedPreferences sp = ctx.getSharedPreferences("config", Context.MODE_PRIVATE); sp.edit().remove(key).commit(); } }