Android启动页无法显示完整图片且有圆角矩形,如何解决?
Android启动页圆角移除与图片完整显示解决办法
一、移除圆角矩形
针对Android 12及以上(API 31+)
Android 12引入的SplashScreen API默认带有圆角,需通过主题配置移除:
- 在
res/values-v31/styles.xml中创建或修改启动页主题:
<style name="SplashTheme" parent="Theme.SplashScreen"> <!-- 指定启动页图片 --> <item name="android:windowSplashScreenDrawable">@drawable/你的启动页图片</item> <!-- 设置圆角半径为0,移除圆角 --> <item name="android:windowSplashScreenCornerRadius">0dp</item> <!-- 可选:关闭系统默认启动动画 --> <item name="android:windowSplashScreenAnimationDuration">0</item> </style>
- 在
AndroidManifest.xml中,给启动Activity指定该主题:
<activity android:name=".SplashActivity" android:theme="@style/SplashTheme"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity>
针对Android 11及以下
旧版本启动页的圆角通常来自背景drawable的shape配置:
- 打开启动页背景文件(一般是
res/drawable/splash_background.xml),若使用shape标签,删除圆角配置或设为0:
<shape xmlns:android="http://schemas.android.com/apk/res/android"> <!-- 移除或修改圆角配置 --> <corners android:radius="0dp"/> <solid android:color="@color/启动页背景色"/> </shape>
- 若直接用图片作为背景,确保主题配置正确:
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar"> <item name="android:windowBackground">@drawable/你的启动页图片</item> </style>
二、让图片完整显示
1. 调整图片缩放模式
若使用layer-list作为启动页背景,配置bitmap的填充方式:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@color/启动页背景色"/> <item> <bitmap android:src="@drawable/你的启动页图片" android:gravity="fill" android:scaleType="fitXY"/> <!-- 拉伸填充全屏,若要保持比例可选centerCrop --> </item> </layer-list>
2. 设置启动页全屏
在启动页主题中添加全屏配置:
<style name="SplashTheme" ...> <item name="android:windowFullscreen">true</item> <item name="android:windowContentOverlay">@null</item> </style>
也可在启动Activity的onCreate方法中添加代码强制全屏:
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); // 隐藏导航栏(可选) getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY); }
3. 适配多屏幕分辨率
- 为不同分辨率提供对应尺寸的图片资源(放置在
drawable-mdpi、drawable-hdpi等目录); - 优先使用9-Patch图片或矢量图,保证在不同屏幕上的显示效果一致。
内容的提问来源于stack exchange,提问作者Danillo Leão Lopes
相关产品推荐
相关产品推荐

