サンプルコード:
// 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");
}
}
「requestWindowFeature」を含めると、エミュレーターでアプリが停止/クラッシュします。理由がわかりません。私はEclipseとAndroidを初めて使用しますが、検索できるものから、正しい順序で物事を行っています。原因のアイデアはありますか?
「setContentView 」の前に「requestWindowFeature」 を使用すると、次のようになります。
02-04 12:35:05.883: E/AndroidRuntime(755): java.lang.RuntimeException: アクティビティ ComponentInfo{com.xxx.yyy/com.xxx.yyy.Main} を開始できません: android.util.AndroidRuntimeException: あなたカスタム タイトルを他のタイトル機能と組み合わせることはできません
「requestWindowFeature」の前に「setContentView」 を使用すると、次のようになります。
02-04 12:32:32.660: E/AndroidRuntime(784): java.lang.RuntimeException: アクティビティ ComponentInfo{com.xxx.yyy/com.xxx.yyy.Main} を開始できません: android.util.AndroidRuntimeException: requestFeature () は、コンテンツを追加する前に呼び出す必要があります