Java 无法将 Appcompat 主题从浅色更改为全色深色
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25162657/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Unable to change Appcompat theme from light to holo dark
提问by Vivek Warde
I am trying to change the theme of my app completely, This is what I modified & tried :
我正在尝试完全改变我的应用程序的主题,这是我修改和尝试的:
styles.xml
in values folder is
styles.xml
在值文件夹中是
<resources>
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Holo">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
</resources>
values-v11 styles.xml
值-v11 styles.xml
<resources>
<!--
Base application theme for API 11+. This theme completely replaces
AppBaseTheme from res/values/styles.xml on API 11+ devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Holo">
<!-- API 11 theme customizations can go here. -->
</style>
</resources>
values-v14 styles.xml
值-v14 styles.xml
<resources>
<!--
Base application theme for API 14+. This theme completely replaces
AppBaseTheme from BOTH res/values/styles.xml and
res/values-v11/styles.xml on API 14+ devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Holo">
<!-- API 14 theme customizations can go here. -->
</style>
</resources>
Mainifest.xml
Mainifest.xml
<application
.....
android:theme="@style/AppTheme" >
.......
</application>
I am using ActionBarActivity
& appcompat_v7
but the app crashes by java.lang.RuntimeException: Unable to start activity ComponentInfo{com...}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity
我正在使用ActionBarActivity
&appcompat_v7
但应用程序崩溃了java.lang.RuntimeException: Unable to start activity ComponentInfo{com...}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity
Am I missing something...?
我是不是错过了什么……?
How can I solve this problem?
我怎么解决这个问题?
Please help...
请帮忙...
Thanks in advance !
提前致谢 !
EDIT:When using Appcompat theme , the theme was light, the code was:
编辑:当使用 Appcompat theme 时,主题很轻,代码是:
So, using appcompat theme my styles.xml
in values folder was
因此,使用 appcompat 主题,我styles.xml
的值文件夹是
<resources>
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
</resources>
values-v11 styles.xml
值-v11 styles.xml
<resources>
<!--
Base application theme for API 11+. This theme completely replaces
AppBaseTheme from res/values/styles.xml on API 11+ devices.
-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
<!-- API 11 theme customizations can go here. -->
</style>
</resources>
values-v14 styles.xml
值-v14 styles.xml
<resources>
<!--
Base application theme for API 14+. This theme completely replaces
AppBaseTheme from BOTH res/values/styles.xml and
res/values-v11/styles.xml on API 14+ devices.
-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- API 14 theme customizations can go here. -->
</style>
</resources>
Mainifest.xml
Mainifest.xml
<application
.....
android:theme="@style/AppTheme" >
.......
</application>
And I dont know how to change appcompat theme from light to holo dark. Please help
而且我不知道如何将 appcompat 主题从浅色更改为全色深色。请帮忙
采纳答案by nstCactus
As tyczj pointed, you need to use Theme.AppCompat
as a parent for your themes if your app uses appcompat_v7
. Theme.AppCompat
is visually the same as Theme.Holo
(dark).
正如 tyczj 所指出的,Theme.AppCompat
如果您的应用使用appcompat_v7
. Theme.AppCompat
在视觉上与Theme.Holo
(暗)相同。
See the article about styling the ActionBaron the Android documentation for more information.
有关详细信息,请参阅Android 文档中有关设置 ActionBar 样式的文章。