android开发(一)启动页的制作

1.启动页延时跳转+沉浸状态栏+启动页图片全屏

public class SplashActivity extends AppCompatActivity {
    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

/*沉浸状态栏,即使状态栏颜色透明*/

       /* View decorView = getWindow().getDecorView();
        decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
        getWindow().setStatusBarColor(Color.TRANSPARENT);*/

/**************************************/

 //去除标题栏  
     //  requestWindowFeature(Window.FEATURE_NO_TITLE);  
        //去掉Activity上面的状态栏
       getWindow().setFlags(WindowManager.LayoutParams. FLAG_FULLSCREEN ,  
                      WindowManager.LayoutParams. FLAG_FULLSCREEN);  

/**************************************/

        setContentView(R.layout.activity_splash);

//延时2秒跳转MainActivity
        new Handler().postDelayed(new Runnable() {
            public void run() {
                Intent intent = new Intent(SplashActivity.this, MainActivity.class);
                startActivity(intent);
            }
        }, 2000);   //2秒
    }
}

activity_splash.xml: (主要代码是android:scaleType="fitXY",x轴,y轴分别拉伸图片)

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >
    <ImageView
        android:id="@+id/splash_bg_img"
        android:src="@mipmap/splash"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="fitXY"
        />
</RelativeLayout>

 2.解决启动白屏问题:

再values/color中添加#90FFFFFF透明色

<color name="transparent">#90FFFFFF</color>

在style中添加主题

</style>
    <style name="AppTransparentTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="android:windowIsTranslucent">true</item>
        <item name="android:windowBackground">@android:color/transparent</item>
    </style>

在Androidmainfest.xml设置:

<activity android:name=".SplashActivity" android:theme="@style/AppTransparentTheme">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

 

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值