Tyd*_*yde 1 java android android-activity actionbarsherlock
我有一个使用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);
....
}
Run Code Online (Sandbox Code Playgroud)
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
Run Code Online (Sandbox Code Playgroud)
为什么会出现这种错误,即使我在调用setContentView之前请求WindowFeature?
在您的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;
....
}
Run Code Online (Sandbox Code Playgroud)