您现在的位置是:首页 > 文章详情

【Android学习笔记】设置App启动页

日期:2018-04-16点击:308

先将启动页放到项目资源中,图片一般是1080*1920的jpg。
新建一个activity,如图:
img_a763700018ae3cc09605475332efed9e.png

img_b41d5bade0574020f19b540ed1f4d620.png

创建成功之后,打开刚刚创建的activity,来进行代码的编写:

public class BZLaunchActivity extends AppCompatActivity { private final int SPLASH_DISPLAY_LENGHT = 2000;//两秒后进入系统,时间可自行调整 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_bzlaunch); //在BZLaunchActivity停留2秒然后进入BZLaunchActivity new android.os.Handler().postDelayed(new Runnable() { @Override public void run() { Intent mainIntent = new Intent(BZLaunchActivity.this,MainActivity.class); BZLaunchActivity.this.startActivity(mainIntent); BZLaunchActivity.this.finish(); } },SPLASH_DISPLAY_LENGHT); } } 

然后去xml配置文件里画界面,配置文件在res/layout与创建时layout同名的的xml文件,代码如下:

<?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout 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" tools:context=".BZLaunchActivity"> <ImageView android:id="@+id/imageView" android:layout_width="wrap_content" android:layout_height="wrap_content" //让图片全屏显示 android:scaleType="fitXY" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" //启动页图片 app:srcCompat="@mipmap/zqq_launch" /> </android.support.constraint.ConstraintLayout>

如果android:scaleType="fitXY"不设置,可能出现启动页图片不全屏的情况。
最后要去AndroidManifest.xml文件中修改一下启动页的activity的位置,未修改之前,MainActivity是在前面的,这个时候运行App,发现并没有启动页,我们需要把启动页的activity调到MainActivity的前面,也就是:

 <activity android:name=".BZLaunchActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity>

好了,完成上面这些,再运行App,就会看到启动页了。

原文链接:https://yq.aliyun.com/articles/615326
关注公众号

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。

持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。

文章评论

共有0条评论来说两句吧...

文章二维码

扫描即可查看该文章

点击排行

推荐阅读

最新文章