2

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

Tom
  • 3,587
  • 9
  • 69
  • 124

2 Answers2

1

take the requestfeature call after setcontentview

    setContentView(R.layout.activity_main);
    titleSupported = this.requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
baboo
  • 1,983
  • 17
  • 23
  • I do not believe that solves my problem. I have expanded my original post. (I get an error as well using your suggestion.) – Tom Feb 04 '13 at 12:38
0

Try to set

<item name="android:windowNoTitle">false</item>

in your theme.

user844541
  • 2,868
  • 5
  • 32
  • 60