简体   繁体   中英

How to add Text to default splash screen in flutter android

I am trying to add Text the bottom of the android default splash screen launch icon in the launch_background.xml located in Flutter App> \android\app\src\main\res\drawable

<?xml version="1.0" encoding="utf-8"?>
<!-- Modify this file to customize your launch splash screen -->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@android:color/white" />

    <!-- You can insert your own image assets here -->
    <item>
        <bitmap
            android:gravity="center"
            android:src="@mipmap/launch_image" />
    </item>
</layer-list>

so far i just tried adding a label tag below the item tag, it didn't work.

A layer-list as used in your drawable, is a way to layer multiple drawables on top of each other. You can not add plain text to the image, but you could define a new drawable which is the text, then add the layer to your list.

Another option is this:

Open Paint or any image editing tool, write your text and save the file as png image

Import png file in drawables and add it in <layer-list> as an item below or above your logo/icon

<item android:bottom="50dp"> set position as you want

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
    android:opacity="opaque">
    <item android:drawable="@color/colorPrimary"/>
    <item>
        <bitmap
            android:gravity="center"
            android:src="@drawable/icon"/>
    </item>
    <item android:bottom="50dp">
        <bitmap
            android:gravity="center"
            android:src="@drawable/myTextImage"/>
    </item>
</layer-list>

It's not possible to add Text on the splash screen. A workaround here is to add the text on the image that's being used on the splash screen.

To add new colors that can be used on the splash screen, create colors.xml in /android/app/src/main/res/values/colors.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <color name="color_name">#ff0000</color>
</resources>

You can now use the color by adding this on launch_background.xml

<item>
  <color android:color="@color/color_name">
</item>

Splash screen is related to Flutter code, and its not platform specific so you should not modify Android xml files. The way to go is to create splash_screen.dart file in which you apply all the logic you need, and than link that file to the mail.dart file by specifying it as home property of MaterialApp widget.

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: SplashScreen(),
    );
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM