相关文章推荐
深情的可乐  ·  Android ...·  1 月前    · 
才高八斗的茶叶  ·  android ...·  1 月前    · 
不要命的汉堡包  ·  WebView全面解析 ·  1 月前    · 
阳刚的硬盘  ·  Android TabLayout ...·  1 月前    · 

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

8 人关注

我有一个单一活动的应用程序,我正在使用SplashScreen API。我为我的图标使用了一个图层列表drawable,但它周围似乎有一个圆形的框架。我试着只使用图标的png文件,但我仍然有同样的问题。

styles.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>

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" />
        android:drawable="@drawable/simple_crypto_logo"
        android:gravity="center" />
</layer-list>

Android Manifest

<?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>

而这是我的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()
    
1 个评论
android
kotlin
AniMike
AniMike
发布于 2021-10-10
2 个回答
Joseph Hawkes-Cates
Joseph Hawkes-Cates
发布于 2022-10-21
已采纳
0 人赞同

这并不理想,但我使用资产工作室将我的闪屏图形作为一个自适应图标导入。在asset studio中,我把我的图标放大,直到它在显示的安全区域内,然后它在我的闪屏上看起来是正确的。我搜索了同样的东西,但无法找到改变图标形状或大小以使其变大的方法。虽然我没有看到谷歌在这方面的明确声明,但共识似乎是,目标是为所有应用程序提供一致的闪屏体验,所以安卓不支持在圆形掩码之外的图标。他们确实表示 here 不过,1/3的图标前景被掩盖了。

Marcus Smith
Marcus Smith
发布于 2022-10-21
0 人赞同

我知道这是个老问题了,但我想我还是要分享一下。我还添加了一个自适应图像,并进行了缩放,使其适合容器布局。这创建了前景和背景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> 

此外,我在我的默认dimens.xml中添加了以下内容

    <dimen name="splashscreen_icon_mask_size_with_background">480dp</dimen>
    <dimen name="splashscreen_icon_size_with_background">308dp</dimen>

由于我将我的主题定义为继承自【替换代码2我需要覆盖图标掩码的大小,然后再覆盖图标的大小。这对我正在开发的设备来说是个好办法。这也意味着我可以根据需要定制每个布局的遮罩尺寸。

还有一些额外的尺寸你可以玩玩,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>