2

当使用点击开始按钮时,我正在设置一个特定的活动全屏。

在这种情况下,showStopButton()称为 。

它运行良好。但是如果我插入

 requestWindowFeature(Window.FEATURE_NO_TITLE); 

然后它崩溃,说明应该在添加内容之前调用它。

我应该如何处理它来设置NO_TITLEw FULL_SCREEN

    private void showStopButton(){

    // requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
    getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
    getWindow().findViewById(android.R.id.content).requestLayout();

    // handle element visibility
((Button)findViewById(R.id.stopButton)).setEnabled(false);
    ((Button)findViewById(R.id.startButton)).setVisibility(View.GONE);
    ((Button)findViewById(R.id.stopButton)).setVisibility(View.VISIBLE);
    ((SeekBar)findViewById(R.id.seekBar1)).setVisibility(View.VISIBLE);
    ((Button)findViewById(R.id.resetButton)).setVisibility(View.GONE);
    ((Button)findViewById(R.id.saveButton)).setVisibility(View.GONE);
}

当重新显示开始按钮时,我有相反的过程,并且它运行正常在这种情况下,我删除了全屏模式

     private void showStartButton(){

        getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
        getWindow().findViewById(android.R.id.content).requestLayout();
        ....
    }
4

6 回答 6

4

它是如此简单......我只需要隐藏ActionBar......然后在回到标准屏幕时显示它......

   private void showStopButton(){
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
        ActionBar actionBar = getActionBar();
        actionBar.hide();
        getWindow().findViewById(android.R.id.content).requestLayout();
于 2014-01-26T09:23:56.373 回答
3

使用 -public class MainActivity extends Activity- 而不是 -public class MainActivity extends ActionBarActivity-

于 2014-12-30T09:52:58.030 回答
2

所以:

@Override
protected void onCreate(
    final Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);

    // Make this activity, full screen
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
        WindowManager.LayoutParams.FLAG_FULLSCREEN);

    // Hide the Title bar of this activity screen
    getWindow().requestFeature(Window.FEATURE_NO_TITLE);

    setContentView(R.layout.main);

    // MORE INIT STUFF HERE...
    //img = (ImageView) findViewById(R.id.imgRandom);
    //btnRandom = (Button) findViewById(R.id.btnRandom);
}
于 2014-01-25T18:22:54.810 回答
1

试试这个......

public class MainActivity extends Activity {

    Context context;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        context = this;

        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);

        setContentView(R.layout.activity_main);
    }
}
于 2015-06-11T06:47:22.783 回答
1

添加这个。

requestWindowFeature(Window.FEATURE_NO_TITLE);

 super.onCreate(savedInstanceState);
 setContentView(R.layout.your activity);
于 2019-05-18T15:42:05.127 回答
0

它可能是这样的:

public class MainActivity extends AppCompatActivity {
   ...
    private final Handler handler = new Handler();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getSupportActionBar().hide(); 
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        setContentView(R.layout.activity_main);

我在警车灯和警报器的例子中使用了上面的代码。当应用程序启动时,灯光动画自动启动,并且警报器在后台响起。

来源:安卓警灯和警笛

在此处输入图像描述

于 2021-03-22T07:57:36.363 回答