我正在创建自定义窗口标题。我用requestWindowFeature和setFeatureInt做了但不行。我不知道这有什么问题。我无法找到错误的来源。
public abstract class MegaActivity extends Activity {
private final int layoutID;
public MegaActivity(final int layoutID) {
super();
this.layoutID = layoutID;
}
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(layoutID);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.window_title);
}
}
public class AsyncTaskTestActivity extends MegaActivity {
public AsyncTaskTestActivity() {
super(R.layout.main);
}
}
window_title.xml
<ImageView
android:id="@+id/header"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:src="@drawable/megadict_icon"/>
<TextView android:layout_width="wrap_content" android:id="@+id/textView1" android:layout_height="wrap_content" android:text="@string/appTitle" android:textSize="16dip" android:textColor="@color/white"></TextView>
</LinearLayout>
错误
07-06 23:42:46.996: ERROR/AndroidRuntime(774): FATAL EXCEPTION: main
07-06 23:42:46.996: ERROR/AndroidRuntime(774): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.asynctask/com.asynctask.AsyncTaskTestActivity}: android.content.res.Resources$NotFoundException: Resource ID #0x7f030002
07-06 23:42:46.996: ERROR/AndroidRuntime(774): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
07-06 23:42:46.996: ERROR/AndroidRuntime(774): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
07-06 23:42:46.996: ERROR/AndroidRuntime(774): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
07-06 23:42:46.996: ERROR/AndroidRuntime(774): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
07-06 23:42:46.996: ERROR/AndroidRuntime(774): at android.os.Handler.dispatchMessage(Handler.java:99)
07-06 23:42:46.996: ERROR/AndroidRuntime(774): at android.os.Looper.loop(Looper.java:123)
07-06 23:42:46.996: ERROR/AndroidRuntime(774): at android.app.ActivityThread.main(ActivityThread.java:4627)
07-06 23:42:46.996: ERROR/AndroidRuntime(774): at java.lang.reflect.Method.invokeNative(Native Method)
07-06 23:42:46.996: ERROR/AndroidRuntime(774): at java.lang.reflect.Method.invoke(Method.java:521)
07-06 23:42:46.996: ERROR/AndroidRuntime(774): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-06 23:42:46.996: ERROR/AndroidRuntime(774): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-06 23:42:46.996: ERROR/AndroidRuntime(774): at dalvik.system.NativeStart.main(Native Method)
07-06 23:42:46.996: ERROR/AndroidRuntime(774): Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f030002
07-06 23:42:46.996: ERROR/AndroidRuntime(774): at android.content.res.Resources.getValue(Resources.java:892)
07-06 23:42:46.996: ERROR/AndroidRuntime(774): at android.content.res.Resources.loadXmlResourceParser(Resources.java:1869)
07-06 23:42:46.996: ERROR/AndroidRuntime(774): at android.content.res.Resources.getLayout(Resources.java:731)
07-06 23:42:46.996: ERROR/AndroidRuntime(774): at android.view.LayoutInflater.inflate(LayoutInflater.java:318)
07-06 23:42:46.996: ERROR/AndroidRuntime(774): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
07-06 23:42:46.996: ERROR/AndroidRuntime(774): at com.android.internal.policy.impl.PhoneWindow.onIntChanged(PhoneWindow.java:992)
07-06 23:42:46.996: ERROR/AndroidRuntime(774): at com.android.internal.policy.impl.PhoneWindow.updateInt(PhoneWindow.java:2397)
07-06 23:42:46.996: ERROR/AndroidRuntime(774): at com.android.internal.policy.impl.PhoneWindow.setFeatureInt(PhoneWindow.java:933)
07-06 23:42:46.996: ERROR/AndroidRuntime(774): at com.asynctask.MegaActivity.onCreate(MegaActivity.java:20)
07-06 23:42:46.996: ERROR/AndroidRuntime(774): at com.asynctask.AsyncTaskTestActivity.onCreate(AsyncTaskTestActivity.java:26)
07-06 23:42:46.996: ERROR/AndroidRuntime(774): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
07-06 23:42:46.996: ERROR/AndroidRuntime(774): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
07-06 23:42:46.996: ERROR/AndroidRuntime(774): ... 11 more
答案 0 :(得分:1)
是AsyncTaskTestActivity启动器活动吗?你是怎么调用那个活动的?问题可能是你的布局,检查你的布局,是否包含错误?如果你仍然得到错误,请暂时注释requestWindowFeature及其相关信息资源问题?你的问题答案可以帮到你