如何在 Splashscreen API 中删除闪屏图标周围的圆形遮罩?

Ani*_*ike 13 android kotlin

我有一个活动应用程序,并且正在使用 SplashScreen API。我使用图层列表可绘制图标作为图标,但它周围似乎有一个圆形框架。我尝试过仅使用图标的 png 文件,但仍然遇到同样的问题。

样式.xml

<style name="Theme.App.Starting" parent="Theme.SplashScreen">
        // Set the splash screen background, animated icon, and animation duration.
        <item name="windowSplashScreenBackground">@color/sailor_blue</item>

        // Use windowSplashScreenAnimatedIcon to add either a drawable or an
        // animated drawable. One of these is required.
        <item name="windowSplashScreenAnimatedIcon">@drawable/splash_screen_layer_list</item>

        // Set the theme of the Activity that directly follows your splash screen.
        <item name="postSplashScreenTheme">@style/Theme.SimpleCrypto.NoActionBar</item>
    </style>
Run Code Online (Sandbox Code Playgroud)

splash_screen_layer_list.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@color/sailor_blue" />
    <item
        android:drawable="@drawable/simple_crypto_logo"
        android:gravity="center" />
</layer-list>
Run Code Online (Sandbox Code Playgroud)

安卓清单

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.decagon.anietie.simplecrypto" >

    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.SimpleCrypto"
        android:name=".SimpleCryptoApplication">
        <activity
            android:name=".MainActivity"
            android:exported="true"
            android:label="@string/app_name"
            android:windowSoftInputMode="adjustResize"
            android:resizeableActivity="true"
            android:theme="@style/Theme.App.Starting"
            tools:targetApi="24" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <meta-data
            android:name="preloaded_fonts"
            android:resource="@array/preloaded_fonts" />
    </application>

</manifest>
Run Code Online (Sandbox Code Playgroud)

这是我的 MainActivity 文件

MainActivity.kt

class MainActivity : AppCompatActivity() {

    private lateinit var appBarConfiguration: AppBarConfiguration
    private lateinit var binding: ActivityMainBinding

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        // Handle the splash screen transition.
        val splashScreen = installSplashScreen()

        binding = ActivityMainBinding.inflate(layoutInflater)
        setContentView(binding.root)
        setSupportActionBar(binding.appBarMain.toolbar)

        val navController = findNavController(R.id.nav_host_fragment_content_main)
        binding.navView?.let {
            appBarConfiguration = AppBarConfiguration(
                setOf(
                    R.id.nav_home, R.id.nav_converter, R.id.nav_wallet, R.id.nav_settings
                ),
                binding.drawerLayout
            )
            setupActionBarWithNavController(navController, appBarConfiguration)
            it.setupWithNavController(navController)
        }

        binding.appBarMain.contentMain.bottomNavView?.let {
            appBarConfiguration = AppBarConfiguration(
                setOf(
                    R.id.nav_home, R.id.nav_converter, R.id.nav_wallet
                )
            )
            setupActionBarWithNavController(navController, appBarConfiguration)
            it.setupWithNavController(navController)
        }

        onDestinationChangedListener()
    }
Run Code Online (Sandbox Code Playgroud)

Jos*_*tes 5

这并不理想,但我使用 Asset Studio 将启动画面图形导入为自适应图标。在 asset studio 中,我缩小了图标,直到它位于显示的安全区域内,然后它在启动屏幕上看起来正确。我搜索了同样的东西,但无法找到更改图标形状或大小以使其更大的方法。尽管我没有看到谷歌对此有任何明确的声明,但共识似乎是,目标是为所有应用程序提供一致的启动屏幕体验,因此 Android 不支持圆形遮罩之外的图标。不过,他们确实在这里声明1/3 的图标前景被遮盖了。


小智 5

我知道这是一个老问题,但我想我会分享。我还添加了一个自适应图像并进行了缩放,以使其适合容器布局。这创建了前景、背景 xml 文件(具有我定义的适当缩放和颜色)。除此之外,它还创建了可绘制的启动图标,保存到 mipmap-anydpi-v26(对于其他人可能有所不同)。一旦我设置了这个,我的启动主题就被定义为:

 <style name="Theme.App.Starting" parent="Theme.SplashScreen.IconBackground">
     <!-- Set the splash screen background, animated icon, and animation duration. -->
     <item name="windowSplashScreenBackground">@color/background_9</item>
     <item name="windowSplashScreenAnimatedIcon">@mipmap/splash_icon</item>
     <item name="postSplashScreenTheme">@style/Theme.Material.Light.NoActionBar.WithStatusColored</item>
 </style> 
Run Code Online (Sandbox Code Playgroud)

另外,我将以下内容添加到我的默认dimens.xml中

    <dimen name="splashscreen_icon_mask_size_with_background">480dp</dimen>
    <dimen name="splashscreen_icon_size_with_background">308dp</dimen>
Run Code Online (Sandbox Code Playgroud)

由于我已将主题定义为继承,因此Theme.SplashScreen.IconBackground我需要覆盖图标蒙版大小,然后覆盖图标大小。这对我正在开发的设备来说是一种享受。这也意味着如果每个布局需要,我可以自定义蒙版尺寸。

您还可以使用其他尺寸,core-splashscreen 版本 1.0.0 的默认尺寸如下:

    <dimen name="splashscreen_icon_mask_size_no_background">410dp</dimen>
    <dimen name="splashscreen_icon_mask_size_with_background">342dp</dimen>
    <dimen name="splashscreen_icon_mask_stroke_no_background">109dp</dimen>
    <dimen name="splashscreen_icon_mask_stroke_with_background">92dp</dimen>
    <dimen name="splashscreen_icon_size">?splashScreenIconSize</dimen>
    <dimen name="splashscreen_icon_size_no_background">288dp</dimen>
    <dimen name="splashscreen_icon_size_with_background">240dp</dimen>
Run Code Online (Sandbox Code Playgroud)