简体   繁体   中英

Hiding android notification bar in actity

I need the code to show and hide the notification bar during an activity.

I try this code:

public void goFullscreen() {
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
    getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
    this.findViewById(android.R.id.content).requestLayout();
}

public void goNonFullscreen() {
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
    getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
    this.findViewById(android.R.id.content).requestLayout();
}

This doesn't work after the content is adding...

Remove the following line from Android Manifest file.

android:theme="@android:style/Theme.Black.NoTitleBar" and check .

Hope it will help you.

This is the code i have used to check it .

public class Main extends Activity {


Button magic,button1,button2;
TextView display;
int random;

private Long startTime=System.currentTimeMillis();
 private Handler handler = new Handler();  

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.ssss);
    button1=(Button)findViewById(R.id.button1);
    button2=(Button)findViewById(R.id.button2);


    button1.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            goFullscreen();
        }
    });

 button2.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            goNonFullscreen();
        }
    });



    }

public void goFullscreen() {
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
    getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
    this.findViewById(android.R.id.content).requestLayout();
}

public void goNonFullscreen() {
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
    getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
    this.findViewById(android.R.id.content).requestLayout();
}     

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM