iis服务器助手广告广告
返回顶部
首页 > 资讯 > 移动开发 >Android App实现闪屏页广告图的全屏显示实例
  • 832
分享到

Android App实现闪屏页广告图的全屏显示实例

2024-04-02 19:04:59 832人浏览 八月长安
摘要

目录1. 适配长屏幕的全面屏2. 适配刘海屏或者水滴屏凹形屏幕的显示模式1. 适配长屏幕的全面屏 至于全屏展示,就得做适配工作,有以下两种方式可进行适配: 在 Android 8.0

1. 适配长屏幕的全面屏

至于全屏展示,就得做适配工作,有以下两种方式可进行适配:

  • Android 8.0(api 26)及更高版本中,我们可以在 标签中使用 android:MaxAspectRatio 来声明其支持的屏幕最大宽高比。
  • 比如我们可以声明最大宽高比为 2.4:
<!-- Render on full screen up to screen aspect ratio of 2.4 -->
<!-- Use a letterbox on screens larger than 2.4 -->
<activity android:maxAspectRatio="2.4">
 ...
</activity>
  • 对于Android 7.1及更低版本,我们可以在 元素中添加名为 android.max_aspect 的 元素

如下所示:

<!-- Render on full screen up to screen aspect ratio of 2.4 -->
<!-- Use a letterbox on screens larger than 2.4 -->
<meta-data android:name="android.max_aspect" android:value="2.4" />

2. 适配刘海屏或者水滴屏

Google 为刘海屏显示方式提供了三种显示模式:

// 默认情况,全屏页面不可用刘海区域,非全屏页面可以进行使用
public static final int LAYOUT_IN_DISPLAY_CUTOUT_MODE_DEFAULT = 0;
// 允许页面延伸到刘海区域
public static final int LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES = 1;
// 不允许使用刘海区域
public static final int LAYOUT_IN_DISPLAY_CUTOUT_MODE_NEVER = 2;

凹形屏幕的显示模式

我们可以通过下面两种方式来指定应用在凹形屏幕的显示模式:

  • 在主题中加入android:windowLayoutInDisplayCutoutMode 属性指定显示模式:
// value-v28/styles.xml
 <style name="AppTheme.Launcher" parent="AppTheme">
        <item name="android:windowBackground">@drawable/branded_launch_screens</item>
        <item name="android:statusBarColor">@color/colorPrimary</item>
        <item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
</style>
  • 通过在代码中指定 Activity 的显示模式

我们可以在 Activity 的 onCreate 中指定凹形屏幕的显示模式:

@Override
protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (Build.VERSION.SDK_INT >= 28) {
            WindowManager.LayoutParams lp = getWindow().getAttributes();
            lp.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
            getWindow().setAttributes(lp);
        }
}

具体使用:需要在values-v27及以上的styles.xml中加入以下主题设置:

<!--实现启动页全屏-->
<style name="Theme.SplashActivity" parent="Theme.AppCompat.NoActionBar">
    <item name="android:windowBackground">@color/white</item>
    <item name="android:windowTranslucentStatus">false</item>
    <item name="android:statusBarColor">@android:color/transparent</item>
    <item name="colorPrimary">@color/main_bg</item>
    <item name="colorPrimaryDark">@color/white</item>
    <item name="colorAccent">@color/white</item>
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowTranslucentNavigation">true</item>
    <item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
</style>

以上就是Android App实现闪屏页广告图的全屏显示实例的详细内容,更多关于Android 闪屏页广告图全屏的资料请关注编程网其它相关文章!

--结束END--

本文标题: Android App实现闪屏页广告图的全屏显示实例

本文链接: https://www.lsjlt.com/news/166443.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作