【发布时间】:2013-02-04 12:22:18
【问题描述】:
示例代码:
// 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 的新手,但是从我可以搜索的内容来看,我正在以正确的顺序做事。有什么想法吗?
使用 "requestWindowFeature" before "setContentView" 我得到:
02-04 12:35:05.883: E/AndroidRuntime(755): java.lang.RuntimeException: 无法开始活动 组件信息{com.xxx.yyy/com.xxx.yyy.Main}: android.util.AndroidRuntimeException:您不能组合自定义标题 与其他标题功能
使用 "setContentView" before "requestWindowFeature" 我得到:
02-04 12:32:32.660: E/AndroidRuntime(784): java.lang.RuntimeException: 无法启动活动 ComponentInfo{com.xxx.yyy/com.xxx.yyy.Main}: android.util.AndroidRuntimeException:必须调用 requestFeature() 在添加内容之前
【问题讨论】:
-
logcat 上有任何堆栈跟踪吗?
-
已添加!抱歉,我没有在最初的问题中添加它。
-
你能告诉我
titleSupported是什么吗? -
我现在已经包含了我想要实现的完整示例。 (以防万一它以任何方式与我的问题相关和/或其他搜索相同问题的人可以在未来的某一天使用它。)
标签: android