【问题标题】:Need to hide and disable status bar in react native using android native code需要使用android原生代码在react native中隐藏和禁用状态栏
【发布时间】:2020-12-11 22:44:47
【问题描述】:

我正在尝试使用 android 本机代码在本机反应中禁用状态栏和主页和历史记录按钮。 React native 为 back btn 提供了功能。

MainActivity.java

package com.kiosk;

import com.facebook.react.ReactActivity;
import com.facebook.react.ReactActivityDelegate;
import com.facebook.react.ReactRootView;
import com.swmansion.gesturehandler.react.RNGestureHandlerEnabledRootView;
import org.devio.rn.splashscreen.SplashScreen;
import android.os.Bundle;

public class MainActivity extends ReactActivity {

  /**
   * Returns the name of the main component registered from JavaScript. This is used to schedule
   * rendering of the component.
   */
   @Override
    protected void onCreate(Bundle savedInstanceState) {
        SplashScreen.show(this);
        FullScreencall();
        super.onCreate(savedInstanceState);
    }

    public void FullScreencall() {
    if(Build.VERSION.SDK_INT < 19){ 
        View v = this.getWindow().getDecorView();
        v.setSystemUiVisibility(View.GONE);
    } else {
            //for higher api versions.    
        View decorView = getWindow().getDecorView(); 
        int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
        decorView.setSystemUiVisibility(uiOptions);
    }
}
  @Override
  protected String getMainComponentName() {
    return "AwesomeProject";
  }
  @Override
protected ReactActivityDelegate createReactActivityDelegate() {
return new ReactActivityDelegate(this, getMainComponentName()) {
@Override
protected ReactRootView createRootView() {
return new RNGestureHandlerEnabledRootView(MainActivity.this);
}
};
}
}

错误获取:

error: cannot find symbol 
        v.setSystemUiVisibility(View.GONE);
                                ^
  symbol:   variable View
  location: class MainActivity

error: cannot find symbol 
        View decorView = getWindow().getDecorView();
        ^
  symbol:   class View
  location: class MainActivity

 error: cannot find symbol 
        int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
                        ^
  symbol:   variable View
  location: class MainActivity

error: cannot find symbol 
        int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
                                                              ^       
  symbol:   variable View
  location: class MainActivity

你有没有在 react native 或 java 中做过,请帮帮我,我卡住了,一些代码 sn-ps 会有所帮助

【问题讨论】:

    标签: java android react-native native


    【解决方案1】:

    您忘记导入 View 类。 将此行添加到 MainActivity.java 的开头:

    import android.view.View;
    

    【讨论】:

    • 我快疯了。谢谢!
    猜你喜欢
    • 2016-07-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-19
    • 2016-06-19
    • 1970-01-01
    相关资源
    最近更新 更多