user12500983
user12500983

Reputation:

Need to hide and disable status bar in react native using android native code

I am trying to disable status bar and home and history buttom in react native using android native code. React native provide function for back btn so did that.

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);
}
};
}
}

ERRORS getting :

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

Have you ever done that in react native or java please help me I stuck, some code snippets will be helpful

Upvotes: 3

Views: 458

Answers (1)

Minh Hưng Trần
Minh Hưng Trần

Reputation: 519

You forgot to import View class. Add this line to the beginning of MainActivity.java:

import android.view.View;

Upvotes: 3

Related Questions