设置沉浸式状态栏
//styles.xml
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
<!-- Customize your theme here. -->
<item name="android:statusBarColor" tools:targetApi="l">@android:color/transparent</item>
<!-- Android 5.0+,设置状态栏全透明透明 -->
<item name="android:editTextBackground">@drawable/rn_edit_text_material</item>
<!-- true: status栏的图标和文字为黑色;false: sstatus栏的图标和文字为白色 -->
<item name="android:windowLightStatusBar">true</item>
</style>
</resources>
支持http请求
//res/xml/network_security_config
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true" />
</network-security-config>
//AndroidManifest.xml
android:usesCleartextTraffic="true"
android:networkSecurityConfig="@xml/network_security_config"
适配安卓X
npx jetifier
报错Error: spawn ./gradlew EACCES
从别的地方拷贝过来的项目运行出错,因为gradlew文件是其他人电脑上的,有权限才能执行。
1.权限问题,react native项目目录下执行
sudo chmod -R 777 node_modules
2.删掉Android文件夹下的gradlew文件,从自己电脑其他的安卓项目里拷贝过来一个。
使用本地html
把html放在android的资源目录下面,并且使用file:///android_asset/路径才能加载!
比如:let source = 'file:///android_asset/dist/index.html'
嗯~~那这样我们每次修改html代码都得复制两份代码,有点不可接受
修改一下,修改html代码后每次编译自动复制到android资源目录下
打开android/app/build.gradle
// Android currently requires the HTML files in React Native to be
// in the Android Assets
// https://github.com/facebook/react-native/pull/17304
task copyReactNativeHTML(type: Copy) {
from '../../app/html'
into 'src/main/assets/html'
}
// Note that you may need to add other build variants
gradle.projectsEvaluated {
bundleDebugJsAndAssets.dependsOn(copyReactNativeHTML)
bundleReleaseJsAndAssets.dependsOn(copyReactNativeHTML)
}
//js代码
var source = ""
if (__DEV__) {
// debug模式
source = require('../html/my.html')
} else {
// release模式
source = (Platform.OS == 'ios') ? require('../html/my.html') : {
uri: "file:///android_asset/html/my.html"
}
}
网友评论