【发布时间】:2012-08-16 05:53:20
【问题描述】:
我制作了一个自定义标题栏,我希望它出现在我的应用程序中的所有活动中。它在我的主要活动中完美运行:
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.main);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title_bar);
但是我的主要活动调用了另一个活动,当我尝试在那里做相同的事情时它失败了:
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.layout_2);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title_bar);
尝试进行 findViewById() 崩溃,我将其中一个包裹在 try/catch 中以查看发生了什么:
TextView tv1;
try {
tv1 = (TextView)findViewById(R.id.header);
}
catch (Exception e) {
Log.d("MyActivity2", "boom");
}
例外说 原因=ClassCastException detailMessage=android.widget.RelativeLayout
我不知道这是什么意思,注意如果我注释掉 requestWindowFeature() 和 会有没有问题getWindow() 调用。
提前感谢您对此的任何见解!!!
【问题讨论】:
标签: android