我正在为选项卡构建应用程序。
- 单击按钮时,我试图显示带有主题的 Activity (比如A )
@android:style/Theme.Dialog
- 在活动A 中,我正在创建操作栏并添加 4 个选项卡。
- 单击选项卡时,我想更改片段。
一切正常,直到我不应用主题应用主题@android:style/Theme.Dialog
后,我得到异常:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ebuilder/com.ebuilder.views.MyTabActivity}: java.lang.NullPointerException
在以下行:
actionBar.addTab(actionBar.newTab().setCustomView(R.layout.tab_home).
setTabListener(homeListener), 0);
我有两个问题:
1. 如果我应用主题对话框会出现什么问题?
2. 我的方法对吗?
如果有人知道另一种方法,请告诉我。
编辑1: *清单文件*
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.vivek"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:targetSdkVersion="14"/>
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".FragmentInsideFragmentTestActivity"
android:label="@string/app_name"
android:theme="@style/Theme.CustomDialog" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
res/values/style.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.CustomDialog" parent="android:style/Theme.Dialog">
<item name="android:windowNoTitle">false</item>
<item name="android:windowActionBar">true</item>
</style>
</resources>
编辑2
05-03 21:42:10.580: D/AndroidRuntime(533): Shutting down VM
05-03 21:42:10.580: W/dalvikvm(533): threadid=1: thread exiting with uncaught exception (group=0x40014760)
05-03 21:42:10.600: E/AndroidRuntime(533): FATAL EXCEPTION: main
05-03 21:42:10.600: E/AndroidRuntime(533): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.vivek/com.vivek.FragmentInsideFragmentTestActivity}: java.lang.IllegalStateException: ActionBarImpl can only be used with a compatible window decor layout
05-03 21:42:10.600: E/AndroidRuntime(533): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1748)
05-03 21:42:10.600: E/AndroidRuntime(533): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1764)
05-03 21:42:10.600: E/AndroidRuntime(533): at android.app.ActivityThread.access$1500(ActivityThread.java:122)
05-03 21:42:10.600: E/AndroidRuntime(533): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1002)
05-03 21:42:10.600: E/AndroidRuntime(533): at android.os.Handler.dispatchMessage(Handler.java:99)
05-03 21:42:10.600: E/AndroidRuntime(533): at android.os.Looper.loop(Looper.java:132)
05-03 21:42:10.600: E/AndroidRuntime(533): at android.app.ActivityThread.main(ActivityThread.java:4025)
05-03 21:42:10.600: E/AndroidRuntime(533): at java.lang.reflect.Method.invokeNative(Native Method)
05-03 21:42:10.600: E/AndroidRuntime(533): at java.lang.reflect.Method.invoke(Method.java:491)
05-03 21:42:10.600: E/AndroidRuntime(533): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
05-03 21:42:10.600: E/AndroidRuntime(533): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
05-03 21:42:10.600: E/AndroidRuntime(533): at dalvik.system.NativeStart.main(Native Method)
05-03 21:42:10.600: E/AndroidRuntime(533): Caused by: java.lang.IllegalStateException: ActionBarImpl can only be used with a compatible window decor layout
05-03 21:42:10.600: E/AndroidRuntime(533): at com.android.internal.app.ActionBarImpl.init(ActionBarImpl.java:214)
05-03 21:42:10.600: E/AndroidRuntime(533): at com.android.internal.app.ActionBarImpl.<init>(ActionBarImpl.java:192)
05-03 21:42:10.600: E/AndroidRuntime(533): at android.app.Activity.initActionBar(Activity.java:1767)
05-03 21:42:10.600: E/AndroidRuntime(533): at android.app.Activity.setContentView(Activity.java:1781)
05-03 21:42:10.600: E/AndroidRuntime(533): at com.vivek.FragmentInsideFragmentTestActivity.onCreate(FragmentInsideFragmentTestActivity.java:47)
05-03 21:42:10.600: E/AndroidRuntime(533): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
05-03 21:42:10.600: E/AndroidRuntime(533): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1712)
05-03 21:42:10.600: E/AndroidRuntime(533): ... 11 more