2017-08-12 29 views
-1

我想要一個深色的主題。如何正確更改UI主題?

我改變了styles.xml如下:

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> 

<style name="AppTheme" parent="android:Theme.Black"> 

,我也試過這要麼不編譯或導致死機一樣許多其他字符串。 Android的監視器的顯示

08-11 20:07:00.938 29773-29773/? I/zygote: Not late-enabling -Xcheck:jni (already on) 
08-11 20:07:00.956 29773-29773/? W/zygote: Unexpected CPU variant for X86 using defaults: x86 
08-11 20:07:01.122 29773-29773/com.example.timothyswan.myapplication I/InstantRun: starting instant run server: is main process 
08-11 20:07:01.283 29773-29805/com.example.timothyswan.myapplication D/OpenGLRenderer: HWUI GL Pipeline 
08-11 20:07:01.457 29773-29805/com.example.timothyswan.myapplication I/OpenGLRenderer: Initialized EGL, version 1.4 
08-11 20:07:01.457 29773-29805/com.example.timothyswan.myapplication D/OpenGLRenderer: Swap behavior 1 
08-11 20:07:01.457 29773-29805/com.example.timothyswan.myapplication W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without... 
08-11 20:07:01.457 29773-29805/com.example.timothyswan.myapplication D/OpenGLRenderer: Swap behavior 0 
08-11 20:07:01.459 29773-29805/com.example.timothyswan.myapplication D/EGL_emulation: eglCreateContext: 0xaa4b1920: maj 2 min 0 rcv 2 
08-11 20:07:01.461 29773-29805/com.example.timothyswan.myapplication D/EGL_emulation: eglMakeCurrent: 0xaa4b1920: ver 2 0 (tinfo 0x9e4aa9f0) 

                         [ 08-11 20:07:01.479 29773:29805 D/   ] 
                         SurfaceInterface::setAsyncMode: set async mode 1 
08-11 20:07:01.493 29773-29805/com.example.timothyswan.myapplication D/EGL_emulation: eglMakeCurrent: 0xaa4b1920: ver 2 0 (tinfo 0x9e4aa9f0) 

和 '運行' 控制檯顯示:

08/11 22:01:07: Launching app 
$ adb shell am start -n "com.example.timothyswan.myapplication/com.example.timothyswan.myapplication.InspirationBasic" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER 
Client not ready yet..Waiting for process to come online 
Connected to process 6973 on device emulator-5554 
Application terminated. 
+0

這不是應用程序的實際崩潰日誌 –

+0

https://medium.com/google-developers/theming-與-程序兼容性,1a292b754b35 –

回答

1

AppCompatActivity(不Activity)的主題必須是Theme.AppCompat的後裔。

因此,檢查您的活動是否延伸AppCompatActivity或不。 如果是這樣,改變它擴展Activity,或使自己的主題,從Theme.AppCompat繼承並應用到你的活動