Sample code:
// activity contains different controls so inherits from Activity
public class Main extends Activity implements OnClickListener, TextWatcher {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
boolean titleSupported = false;
if (true) { // for on/off testing
titleSupported = this.requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
}
setContentView(R.layout.activity_main);
// see: http://stackoverflow.com/questions/3438276/change-title-bar-text-in-android
if (titleSupported)) {
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.titlebar);
final TextView myTitleText = (TextView) findViewById(R.id.myTitle);
if ( myTitleText != null ) {
myTitleText.setText("@string/app_name");
}
}
When I include the "requestWindowFeature" the app stops/crashes in emulator. I don't understand why. I am new to Eclipse and Android, but from what I can search, I am doing things in the correct order. Any ideas of the cause?
with "requestWindowFeature" before "setContentView" I get:
02-04 12:35:05.883: E/AndroidRuntime(755): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xxx.yyy/com.xxx.yyy.Main}: android.util.AndroidRuntimeException: You cannot combine custom titles with other title features
With "setContentView" before "requestWindowFeature" I get:
02-04 12:32:32.660: E/AndroidRuntime(784): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xxx.yyy/com.xxx.yyy.Main}: android.util.AndroidRuntimeException: requestFeature() must be called before adding content