Android 启动页延伸至状态栏

栏目: IT技术 · 发布时间: 4年前

内容简介:作者:码后泡链接:https://www.jianshu.com/p/c35a507f1e3e

code小生 一个专注大前端领域的技术平台 公众号回复 Android 加入安卓技术群

作者:码后泡

链接:https://www.jianshu.com/p/c35a507f1e3e

声明:本文已获 码后泡 授权发表,转发等请联系原作者授权

启动页加载的资源延伸至状态栏展示,如下图:

Android 启动页延伸至状态栏

我实现的方式是给activity设置主题和在activity中添加一句代码:

主题:这个主题你要在Manifest.xml文件里边配置到你的启动页activity

<style name="FullscreenTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!--这个是预先设置的背景图片-->
        <item name="android:windowBackground">@drawable/splash_bg</item>
        <!--设置过渡效果,禁用窗口的预览动画-->
        <item name="android:windowDisablePreview">true</item>
        <item name="android:windowNoTitle">true</item>
        <item name="android:statusBarColor">@android:color/transparent</item>
        <item name="android:navigationBarColor">@android:color/transparent</item>
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
        <item name="android:fullBackupOnly">true</item>
        <item name="android:screenOrientation">portrait</item>
        <item name="android:windowSoftInputMode">stateHidden</item>
        <item name="android:configChanges">orientation|keyboardHidden|screenSize</item>
</style>

我们往往会在背景中加入自己的Logo,splash_bg.xml的代码:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
    android:opacity="opaque">
    <!--opacity="opaque"  activity不透明的-->
    <item android:drawable="@color/white" />
    <item
        android:gravity="bottom"
        android:scaleType="center">
        <!--tilMode属性用于定义背景的显示模式-->

        <shape android:shape="rectangle">
            <solid android:color="@color/white" />
        </shape>

    </item>
 <!-- android:drawable="@drawable/logo"  你的logo-->
    <item
        android:width="155dp"
        android:height="58dp"
        android:drawable="@drawable/logo"
        android:gravity="bottom|center_horizontal"
        android:bottom="@dimen/dp_15"/>

</layer-list>

最后别忘了在你的activity中加如以下代码:

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //是否全屏
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
    }

以下顺便贴上启动页activity的布局文件:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="newmatch.zbmf.com.testapplication.activitys.SplashActivity">

    <androidx.appcompat.widget.AppCompatImageView
        android:id="@+id/screenIV"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginBottom="@dimen/dp_88"
        android:gravity="center"
        android:keepScreenOn="true"
        android:scaleType="centerCrop"
        android:visibility="visible" />

    <androidx.appcompat.widget.AppCompatButton
        android:id="@+id/skipAd"
        android:layout_width="@dimen/dp_45"
        android:layout_height="@dimen/dp_25"
        android:layout_alignParentTop="true"
        android:layout_alignParentEnd="true"
        android:layout_marginTop="@dimen/dp_30"
        android:layout_marginEnd="@dimen/dp_15"
        android:background="@drawable/skip_ad_bg"
        android:gravity="center"
        android:padding="@dimen/dp_3"
        android:text="@string/skip"
        android:textColor="@color/white"
        android:textSize="@dimen/sp_14" />

</RelativeLayout>

skip_ad_bg.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid android:color="@color/deepPurple_translate" />
    <stroke
        android:width="@dimen/dp_0_5"
        android:color="@color/white" />
    <corners android:radius="@dimen/dp_45" />
</shape>

至此,你也可以实现启动页全屏的展示,再也不用在启动页留一条状态栏的黑边了

顺带补充一点:一般启动页都会加载图片或者动态小视频的广告,我的做法是用户首次安装应用不显示广告只显示默认的启动页背景,首次启动的同时将广告资源存储到本地,当用户下次打开app时开始展示广告。


以上所述就是小编给大家介绍的《Android 启动页延伸至状态栏》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

算法技术手册(影印版第2版)(英文版)

算法技术手册(影印版第2版)(英文版)

(美)乔治·T·海涅曼//加里·波利斯//斯坦利·塞克欧 / 东南大学 / 2017-10-01 / 96.0

一起来看看 《算法技术手册(影印版第2版)(英文版)》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

html转js在线工具
html转js在线工具

html转js在线工具