我尝试创建透明活动,因此我为活动提供以下样式:
<style name="Theme.Transparent" parent="android:Theme">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">true</item>
<item name="android:backgroundDimEnabled">false</item>
</style>
我不知道为什么会崩溃应用程序。
知道为什么吗?
编辑:这是我的logcat,我是新手,所以我对调试它并不了解。05-14 06:25:08.919 1218-1307/system_process I/ActivityManager﹕ START u0 {cmp=com.myapp.enterprise/.GreenViewActivity} from uid 10057 on display 0
05-14 06:25:08.924 1218-1265/system_process W/AudioTrack﹕ AUDIO_OUTPUT_FLAG_FAST denied by client
05-14 06:25:08.959 6744-6744/com.myapp.enterprise D/AndroidRuntime﹕ Shutting down VM
05-14 06:25:08.959 6744-6744/com.myapp.enterprise E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.myapp.enterprise, PID: 6744
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myapp.enterprise/com.myapp.enterprise.GreenViewActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5257)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.support.v7.app.AppCompatDelegateImplBase.onCreate(AppCompatDelegateImplBase.java:113)
at android.support.v7.app.AppCompatDelegateImplV7.onCreate(AppCompatDelegateImplV7.java:146)
at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:59)
at com.myapp.enterprise.GreenViewActivity.onCreate(GreenViewActivity.java:13)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5257)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
05-14 06:25:08.965 1218-7949/system_process W/ActivityManager﹕ Force finishing activity 1 com.myapp.enterprise/.GreenViewActivity
05-14 06:25:08.978 1218-7949/system_process W/ActivityManager﹕ Force finishing activity 2 com.myapp.enterprise/.NoteActivity
05-14 06:25:09.083 1218-2572/system_process I/OpenGLRenderer﹕ Initialized EGL, version 1.4
05-14 06:25:09.110 1218-2572/system_process W/EGL_emulation﹕ eglSurfaceAttrib not implemented
05-14 06:25:09.110 1218-2572/system_process W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0x9d932880, error=EGL_SUCCESS
05-14 06:25:09.490 1218-1236/system_process W/ActivityManager﹕ Activity pause timeout for ActivityRecord{5ebb3cd u0 com.myapp.enterprise/.GreenViewActivity t546 f}
答案 0 :(得分:0)
只需在Menifest xml文件的活动中使用此主题即可创建透明活动
android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen"
答案 1 :(得分:0)
您需要使用parent="@style/Theme.AppCompat"
作为父级而非当前parent="android:Theme"
答案 2 :(得分:0)
如果您要从AppCompactActivity或ActionBarActivity扩展您的活动,则必须使用您的父主题
<style name="Theme.Transparent" parent="@style/Theme.AppCompat.Light.DarkActionBar">
适用于整个应用程序或仅用于激活