1

我有一个使用 ActionBarSherlock 的活动。现在我想在该操作栏中显示一个不确定的进度,并按照 ActionBarSherlock 中的示例进行操作:

public class MainMenu extends SimpleWebActivity implements BackgroundBrowserReciever {
    private Boolean windowFeatureCalled;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
        super.onCreate(savedInstanceState);

        this.windowFeatureCalled = true;
        setContentView(R.layout.main_menu);
                ....
    }

SimpleWebActivity 是扩展 SherlockActivity 的抽象类。

但是当我尝试加载该活动时,我收到以下错误:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.dalthed.tucan/com.dalthed.tucan.ui.MainMenu}: android.util.AndroidRuntimeException: requestFeature() must be called before adding content

为什么会发生此错误,即使我在调用 setContentView 之前请求了 WindowFeature?

4

2 回答 2

5

在您的 Super.onCreate 之后移动它,这应该可以解决您的问题。

     @Override
        public void onCreate(Bundle savedInstanceState) {

            super.onCreate(savedInstanceState);

//HERE
 requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);

            setContentView(R.layout.main_menu);
  this.windowFeatureCalled = true;
                    ....
        }
于 2012-05-31T19:00:56.407 回答
1

让我们试试这个它对我有用

@Override
    public void onCreate(Bundle savedInstanceState) {

//HERE
        requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);

        super.onCreate(savedInstanceState);

        setContentView(R.layout.main_menu);

         this.windowFeatureCalled = true;
                ....
    }
于 2013-02-19T08:49:26.570 回答