android - requestWindowFeature(Window.FEATURE_NO_TITLE) 异常

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21354365/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 04:24:28  来源:igfitidea点击:

android - requestWindowFeature(Window.FEATURE_NO_TITLE) exception

androidandroid-fullscreen

提问by aliosmeen

I am setting a specific activity full screen when the use hits a START button.

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

In this case the showStopButton()is called .

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

It's running fine. But if I insert

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

 requestWindowFeature(Window.FEATURE_NO_TITLE); 

then it crashes , stating that it should be call before adding content.

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

How should I handle it to set NO_TITLEw the FULL_SCREEN??

我应该如何处理它来设置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);
}

I have the reverse process when the START button is redisplayed , and it's running back fine In this case I remove the fullscreen mode

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

     private void showStartButton(){

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

采纳答案by Phant?maxx

So:

所以:

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

回答by

it's so simple ... I just need to hide the ActionBar... then show it when back to standard screen...

太简单了...我只需要隐藏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();

回答by aliosmeen

Use -public class MainActivity extends Activity- instead of -public class MainActivity extends ActionBarActivity-

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

回答by M.S

Try this one......

试试这个……

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

回答by Pavan jinka

Add this.

添加这个。

requestWindowFeature(Window.FEATURE_NO_TITLE);

before

 super.onCreate(savedInstanceState);
 setContentView(R.layout.your activity);