在 Android Studio 中更改项目主题?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21762203/
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
Change the project theme in Android Studio?
提问by ioan ghip
I created some project using the light theme and now I want to change it to dark and I can't figure out how to do that. BTW, I'm not asking on how to do it in code, just how to change the project's default theme.
我使用浅色主题创建了一些项目,现在我想将其更改为深色,但我不知道该怎么做。顺便说一句,我不是在问如何在代码中做到这一点,而是如何更改项目的默认主题。
采纳答案by Shahzeb
In the AndroidManifest.xml, under the application tag, you can set the theme of your choice. To customize the theme, press Ctrl + Click
on android:theme = "@style/AppTheme"
in the Android manifest file. It will open styles.xml
file where you can change the parent attribute of the style tag.
在 AndroidManifest.xml 的 application 标签下,您可以设置您选择的主题。要自定义主题,按Ctrl + Click
上android:theme = "@style/AppTheme"
在Android清单文件。它将打开styles.xml
文件,您可以在其中更改样式标记的父属性。
At parent=
in styles.xml
you can browse all available styles by using auto-complete inside the ""
. E.g. try parent="Theme."
with your cursor right after the .
and then pressing Ctrl + Space
.
在parent=
中styles.xml
您可以使用自动完成内浏览所有可用的样式""
。例如parent="Theme."
,在 之后尝试使用光标.
,然后按Ctrl + Space
。
You can also preview themes in the preview window in Android Studio.
您还可以在 Android Studio 的预览窗口中预览主题。
回答by Mohamed Rozza
Note : This answer is now out-of-date. This changes the theme in "preview" only as @imjohnking and @john-ktejik pointed out. As @Shahzeb mentioned, theme can modified in res>values>styles
注意:此答案现已过时。仅如@imjohnking 和@john-ktejik 指出的那样,这会更改“预览”中的主题。正如@Shahzeb 提到的,主题可以在 res>values>styles 中修改
Android Studio 0.8.2 provides a slightly easier way to change the theme. In the preview window, you can select the theme of "Holo.Light.DarkActionBar" by clicking on the theme combo box just above the phone.
Android Studio 0.8.2 提供了一种更简单的更改主题的方法。在预览窗口中,您可以通过单击手机正上方的主题组合框来选择“Holo.Light.DarkActionBar”主题。
Or do a ctrl + click on the @style/AppTheme in the Android manifest file. It will open styles.xml file where you can change the parent attribute of the style tag.
或者按 ctrl + 单击 Android 清单文件中的 @style/AppTheme。它将打开styles.xml 文件,您可以在其中更改样式标记的父属性。
- Theme.Holo for a "dark" theme.
- Theme.Holo.Light for a "light" theme.
- Theme.Holo 用于“黑暗”主题。
- Theme.Holo.Light 用于“轻”主题。
When using the Support Library, you must instead use the Theme.AppCompat themes:
使用支持库时,您必须改用 Theme.AppCompat 主题:
- Theme.AppCompat for the "dark" theme.
- Theme.AppCompat.Light for the "light" theme.
- Theme.AppCompat.Light.DarkActionBar for the light theme with a dark action bar.
- Theme.AppCompat 用于“深色”主题。
- Theme.AppCompat.Light 为“轻”主题。
- Theme.AppCompat.Light.DarkActionBar 用于带有深色操作栏的浅色主题。
Source http://forums.udacity.com/questions/100200635/choosing-theme-in-android-studio-08x
来源http://forums.udacity.com/questions/100200635/choosing-theme-in-android-studio-08x
回答by Art
In Manifest theme sets with style name (AppTheme and myDialog)/ You can set new styles in styles.xml
在带有样式名称的清单主题集(AppTheme 和 myDialog)中/您可以在styles.xml 中设置新样式
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MyActivity2"
android:label="@string/title_activity_my_activity2"
android:theme="@style/myDialog"
>
</activity>
</application>
styles.xml example
样式.xml 示例
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="android:Theme.Black">
<!-- Customize your theme here. -->
</style>
<style name="myDialog" parent="android:Theme.Dialog">
</style>
In parent you set actualy the theme
在父级中,您实际上设置了主题