加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

react-native APP图标和Splash(Android)

发布时间:2020-12-15 09:31:10 所属栏目:百科 来源:网络整理
导读:先来看下常用手机分辨率 // mdpi 480*320// hdpi 800*480// xhdpi 1280*720// xhdpi 1920*1080 修改APP名称 找到android/app/src/main/AndroidManifest.xml application android:name = ".MainApplication " android:label = "@string/app_name " android:ic

先来看下常用手机分辨率

//   mdpi    480*320
//   hdpi    800*480
//   xhdpi   1280*720
//   xhdpi   1920*1080

修改APP名称

找到android/app/src/main/AndroidManifest.xml

<application android:name=".MainApplication" android:label="@string/app_name" android:icon="@mipmap/ic_launcher" android:allowBackup="false" android:theme="@style/AppTheme"> </application> 

找到 android:label = "@string/app_name"。这个对应的就是APP的名称

进入:android/app/src/main/res/valuse/strings.xml目录下

<resources> <string name="app_name">APP名称</string> </resources> 

修改APP图标

1、找到读取APP图标的地方

进入目录::android/app/src/main/AndroidManifest.xml

<application android:name=".MainApplication" android:label="@string/app_name" android:icon="@mipmap/ic_launcher" android:allowBackup="false" android:theme="@style/AppTheme"> </application> 

可以看到,icon是在mipmap文件下的ic_launcher图片,因此,在android/app/src/main/res下新建mipmap_hdpi,mipmap_mdpi,mipmap_xhdpi,mipmap_xxhdpi文件,里面分别存放图片ic_launcher,
分辨率分别为72x72,48x48,96x96,144x144,192*192

修改Splash

附上地址:https://github.com/crazycodeboy/react-native-splash-screen

安装
npm install react-native-splash-screen --save react-native link react-native-splash-screen 
检查 link

settings.gradle

include ‘:react-native-splash-screen‘ project(‘:react-native-splash-screen‘).projectDir = new File(rootProject.projectDir,‘../node_modules/react-native-splash-screen/android‘) 

build.gradle

compile project(‘:react-native-splash-screen‘)

MainApplication.java

import org.devio.rn.splashscreen.SplashScreenReactPackage; new SplashScreenReactPackage() 
启动页设置

在android/app/src/main/res下新建layout文件,launch_screen.xml

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/launch_screen"> </LinearLayout> 

MainActivity.java

import android.os.Bundle; import org.devio.rn.splashscreen.SplashScreen; protected void onCreate(Bundle savedInstanceState) { SplashScreen.show(this); // <--添加这一句 super.onCreate(savedInstanceState); } 

在android/app/src/main/res下新建drawable_hdpi,drawable_mdpi,drawable_xhdpi,drawable_xxhdpi文件,里面分别存放图片launch_screen,
分辨率分别为文章开头提到的分辨率,
在你首个页面增加

import SplashScreen from ‘react-native-splash-screen‘; componentDidMount() { SplashScreen.hide(); //关闭启动屏幕 } 

至此,整个启动页完成了

?
?
1人点赞
?
React-Native

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读