简体   繁体   English

如何在不更改MainActivity的情况下在React Native App中隐藏android系统的底部导航栏? 也许通过AndroidManifest?

[英]How to hide android system' s bottom navigation bar in React Native App without changing MainActivity? Maybe through AndroidManifest?

I want to hide the system's bottom navigation bar. 我想隐藏系统的底部导航栏。 I used "react-native-navigation-bar-color" but it causes a build error, strangely while release build only. 我使用了“ react-native-navigation-bar-color”,但它会导致生成错误,奇怪的是仅在发布版本中。

I thought I could remove this package(react-native-navigation-bar-color) and permanently hide the navbar by changing MainActivity but the MainActivity in React Native does not inherit AppCompatActivity in order for it to have "onCreate" method in which I can write the code(as per android studio documentation) to hide. 我以为我可以删除此包(react-native-navigation-bar-color)并通过更改MainActivity永久隐藏导航栏,但是React Native中的MainActivity不会继承AppCompatActivity以便它具有“ onCreate”方法,我可以在其中编写代码(根据android studio文档)隐藏。

Following is the build error: /Users/yashjaveri/.gradle/caches/transforms-1/files-1.1/appcompat-v7-28.0.0.aar/f688ce916ebedb5188b6c1f4470868ef/res/values-v28/values-v28.xml:9:5-12:13: AAPT: error: resource android:attr/dialogCornerR adius not found. 以下是构建错误:/Users/yashjaveri/.gradle/caches/transforms-1/files-1.1/appcompat-v7-28.0.0.aar/f688ce916ebedb5188b6c1f4470868ef/res/values-v28/values-v28.xml:9: 5-12:13:AAPT:错误:找不到资源android:attr / dialogCornerR adius。

/Users/yashjaveri/Documents/React/ReactNative_Projects/SLink/node_modules/react-native-navigation-bar-color/android/build/intermediates/res/merged/release/values-v28/values-v28.xml:11: AAPT: error: resource android:attr/dialogCornerRadius not found. /Users/yashjaveri/Documents/React/ReactNative_Projects/SLink/node_modules/react-native-navigation-bar-color/android/build/intermediates/res/merged/release/values-v28/values-v28.xml:11:AAPT :错误:找不到资源android:attr / dialogCornerRadius。

/Users/yashjaveri/.gradle/caches/transforms-1/files-1.1/appcompat-v7-28.0.0.aar/f688ce916ebedb5188b6c1f4470868ef/res/values/values.xml:1304:5-69: AAPT: error: resource android:attr/fontVariationSettings not found. /Users/yashjaveri/.gradle/caches/transforms-1/files-1.1/appcompat-v7-28.0.0.aar/f688ce916ebedb5188b6c1f4470868ef/res/values/values.xml:1304:5-69:AAPT:错误:资源android :attr / fontVariationSettings找不到。

/Users/yashjaveri/.gradle/caches/transforms-1/files-1.1/appcompat-v7-28.0.0.aar/f688ce916ebedb5188b6c1f4470868ef/res/values/values.xml:1304:5-69: AAPT: error: resource android:attr/ttcIndex not found. /Users/yashjaveri/.gradle/caches/transforms-1/files-1.1/appcompat-v7-28.0.0.aar/f688ce916ebedb5188b6c1f4470868ef/res/values/values.xml:1304:5-69:AAPT:错误:资源android :attr / ttcIndex找不到。

error: failed linking references. 错误:链接引用失败。

FAILURE: Build failed with an exception. 失败:构建失败,发生异常。

  • What went wrong: Execution failed for task ':react-native-navigation-bar-color:verifyReleaseResources'. 出了什么问题:任务':react-native-navigation-bar-color:verifyReleaseResources'的执行失败。

    com.android.ide.common.process.ProcessException: Failed to execute aapt com.android.ide.common.process.ProcessException:无法执行aapt

Please help me out either by providing way to hide navbar permanently in react-native or by suggesting any other npm package() or by helping me solve the release build error, as my app has a video screen which requires full screen mode. 由于我的应用程序具有需要全屏模式的视频屏幕,因此请通过提供一种方法将其永久隐藏在react-native或建议其他npm package()或帮助我解决发布版本错误,来帮助我。

Thank you 谢谢

截图

Hide the Navigation Bar 隐藏导航栏

You can hide the navigation bar using the SYSTEM_UI_FLAG_HIDE_NAVIGATION flag. 您可以使用SYSTEM_UI_FLAG_HIDE_NAVIGATION标志隐藏导航栏。 This snippet hides both the navigation bar and the status bar: 此代码段同时隐藏了导航栏和状态栏:

ote the following: 请注意以下几点:

@Reactmethod
public void hidenavigationbar() {
View decorView = getWindow().getDecorView();
// Hide both the navigation bar and the status bar.
// SYSTEM_UI_FLAG_FULLSCREEN is only available on Android 4.1 and higher, but as
// a general rule, you should design your app to hide the status bar whenever you
// hide the navigation bar.
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
          | View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
}
  • With this approach, touching anywhere on the screen causes the navigation bar (and status bar) to reappear and remain visible. 使用这种方法,触摸屏幕上的任何位置都会使导航栏(和状态栏)重新出现并保持可见。 The user interaction causes the flags to be be cleared. 用户交互导致标记被清除。
  • Once the flags have been cleared, your app needs to reset them if you want to hide the bars again. 清除标志后,如果您想再次隐藏条,则您的应用需要重置它们。 See Responding to UI Visibility Changes for a discussion of how to listen for UI visibility changes so that your app can respond accordingly. 请参阅“响应UI可见性更改”,以获取有关如何侦听UI可见性更改以使您的应用程序做出相应响应的讨论。
  • Where you set the UI flags makes a difference. 设置UI标志的位置有所不同。 If you hide the system bars in your activity's onCreate() method and the user presses Home, the system bars will reappear. 如果您在活动的onCreate()方法中隐藏系统栏,并且用户按下Home键,则系统栏将重新出现。 When the user reopens the activity, onCreate() won't get called, so the system bars will remain visible. 当用户重新打开活动时,不会调用onCreate(),因此系统栏将保持可见。 If you want system UI changes to persist as the user navigates in and out of your activity, set UI flags in onResume() or onWindowFocusChanged(). 如果您希望系统UI更改在用户进入和离开您的活动时持续存在,请在onResume()或onWindowFocusChanged()中设置UI标志。
  • The method setSystemUiVisibility() only has an effect if the view you call it from is visible. 方法setSystemUiVisibility()仅在从中调用的视图可见时才有效。
  • Navigating away from the view causes flags set with setSystemUiVisibility() to be cleared. 从视图中导航会使使用setSystemUiVisibility()设置的标志被清除。

this link about my answer 关于我的答案的此链接

OR Use this link 或使用此链接

import FullScreen from 'react-native-full-screen'
FullScreen.onFullScreen()
FullScreen.offFullScreen()

an article referenced in writing another answer . 以书面形式引用另一个答案的文章。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在本机反应中隐藏特定屏幕上的底部导航栏? - How to hide bottom navigation bar on a specific screen in react native? 如何在 React Native 中隐藏底部操作栏 - How to hide the Bottom action bar in React Native 如何在底部导航栏中访问类的this.state(React Native) - How to access this.state of a class in Bottom navigation bar (React Native) react-native bottomTabNavigator被Android系统导航栏部分覆盖 - react-native bottomTabNavigator is partially covered by Android system navigation bar React Navigation - 底部导航栏中的条件隐藏项 - React Navigation - conditional hide item in bottom navigation bar Header 标题不随底部导航而改变 React Native Navigation v5 - Header title not changing with bottom navigation React Native Navigation v5 在集成 React native 和 android 应用程序时更改 MainActivity 条目 - Changing MainActivity entry while integrating React native and android application 使用时如何从底部标签栏隐藏“SPECIFIC TAB BAR ITEM”:@react-navigation/bottom-tabs - How to hide a "SPECIFIC TAB BAR ITEM" from a bottom tab bar when using: @react-navigation/bottom-tabs React Navigation V5 在 Stack Navigator 中隐藏底部标签栏 - React Navigation V5 hide Bottom tab bar in Stack Navigator 如何在stackNavigator内部的屏幕中隐藏底部栏 - how to hide bottom bar from in a screen inside stackNavigator react-navigation
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM