我有一个使用ActionBarSherlock的Activity。现在我想在该操作栏中显示一个Indeterminate Progress,并按照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的抽象类。
但是当我尝试加载该Activity时,我收到以下错误:
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?
答案 0 :(得分: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;
....
}
答案 1 :(得分:1)
让我们尝试一下这对我有用
@Override
public void onCreate(Bundle savedInstanceState) {
//HERE
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
super.onCreate(savedInstanceState);
setContentView(R.layout.main_menu);
this.windowFeatureCalled = true;
....
}