这篇文章主要为大家介绍了Android App实现闪屏页广告图的全屏显示实例,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪
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 闪屏页广告图全屏的资料请关注编程学习网其它相关文章!
沃梦达教程
本文标题为:Android App实现闪屏页广告图的全屏显示实例
猜你喜欢
- Flutter实现底部和顶部导航栏 2022-08-31
- iOS 对当前webView进行截屏的方法 2023-03-01
- SurfaceView播放视频发送弹幕并实现滚动歌词 2023-01-02
- 作为iOS开发,这道面试题你能答出来,说明你基础很OK! 2023-09-14
- Android studio实现动态背景页面 2023-05-23
- Android实现监听音量的变化 2023-03-30
- Android实现轮询的三种方式 2023-02-17
- 最好用的ios数据恢复软件:PhoneRescue for Mac 2023-09-14
- Android MaterialButton使用实例详解(告别shape、selector) 2023-06-16
- 详解flutter engine 那些没被释放的东西 2022-12-04
