机器人 - requestWindowFeature(Window.FEATURE_NO_TITLE)异常 [英] android - requestWindowFeature(Window.FEATURE_NO_TITLE) exception

查看:325
本文介绍了机器人 - requestWindowFeature(Window.FEATURE_NO_TITLE)异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用击中START键我设置一个特定的活动全屏。

在这种情况下, showStopButton()被调用。

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

  requestWindowFeature(Window.FEATURE_NO_TITLE);

那么它崩溃,指出它应该是在添加内容之前调用。

我应该如何处理它设置 NO_TITLE W上的 FULL_SCREEN ??

 私人无效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();    //把手元件知名度
((按钮)findViewById(R.id.stopButton))的setEnabled(假)。
    ((按钮)findViewById(R.id.startButton))setVisibility(View.GONE)。
    ((按钮)findViewById(R.id.stopButton))setVisibility(View.VISIBLE)。
    ((搜索栏)findViewById(R.id.seekBar1))setVisibility(View.VISIBLE)。
    ((按钮)findViewById(R.id.resetButton))setVisibility(View.GONE)。
    ((按钮)findViewById(R.id.saveButton))setVisibility(View.GONE)。
}

我有当START键重新显示相反的过程,它的细跑
在这种情况下,我删除了全屏模式

 私人无效showStartButton(){        。getWindow()addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
        。getWindow()clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
        。getWindow()findViewById(android.R.id.content).requestLayout();
        ....
    }


解决方案

所以:

  @覆盖
保护无效的onCreate(
    最终捆绑savedInstanceState)
{
    super.onCreate(savedInstanceState);    //使这个活动,全屏​​幕
    getWindow()。setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
        WindowManager.LayoutParams.FLAG_FULLSCREEN);    //隐藏此活动画面的标题栏
    。getWindow()requestFeature(Window.FEATURE_NO_TITLE);    的setContentView(R.layout.main);    //更多INIT的东西在这里...
    // IMG =(ImageView的)findViewById(R.id.imgRandom);
    // btnRandom =(按钮)findViewById(R.id.btnRandom);
}

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

In this case the showStopButton() is called .

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_TITLE w the 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

     private void showStartButton(){

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

解决方案

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

这篇关于机器人 - requestWindowFeature(Window.FEATURE_NO_TITLE)异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆