代码之家  ›  专栏  ›  技术社区  ›  Taylon Assis

如何根据设备分辨率在React Native中设置小通知图标

  •  2
  • Taylon Assis  · 技术社区  · 6 年前

    我正在接收通知,现在使用默认图标。 我想定制它们,但我真的没时间设置图标。

    使用 react-native-firebase notifications .

    我已经在网上创建了合适大小的图标 notification icons generator .

    然后我用正确的名字在不同的地方创建了目录,如下所示(Android):

    android/app/src/main/res/drawable-mdpi/ (24x24)
    
    android/app/src/main/res/drawable-hdpi/ (36x36)
    
    android/app/src/main/res/drawable-xhdpi/ (48x48)
    
    android/app/src/main/res/drawable-xxhdpi/ (72x72)
    
    android/app/src/main/res/drawable-xxxhdpi/ (96x96)
    

    现在,我想得到正确大小的图像并在这里解决它。

    var notification = new firebase.notifications.Notification({
                      sound: 'default',
                      show_in_foreground: true,
                 })
                 .android.setPriority(firebase.notifications.Android.Priority.High)
                 .android.setChannelId("channel")
                 .android.setSmallIcon(  <How do I put icon paths here?>  ); 
    

    我读过一些文件和指导方针,但我真的不知道。 引用这些路径的正确方法是什么?

    1 回复  |  直到 6 年前
        1
  •  3
  •   Dhaval Solanki Sandunika Wijerathne    6 年前

    我们建议将以下行放入您的清单中,然后将所有不同大小的图标放入mipmap文件夹后,它将根据设备的分辨率调用。

    <meta-data android:name="com.google.firebase.messaging.default_notification_icon" android:resource="@mipmap/ic_noti_icon" />