0

我需要代码在活动期间显示和隐藏通知栏。

我试试这段代码:

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

添加内容后这不起作用...

4

1 回答 1

1

从 Android 清单文件中删除以下行。

android:theme="@android:style/Theme.Black.NoTitleBar" 并检查 .

希望它会帮助你。

这是我用来检查它的代码。

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();
}     
于 2013-01-03T14:44:38.400 回答