如何更改Android应用程序的主题?

Adh*_*ham 7 android

我正在开发一个Android应用程序,我想改变应用程序的颜色和主题.我怎样才能做到这一点?

Bry*_*nny 9

开发指南解释了如何应用主题和样式.

这个:

<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textColor="#00FF00"
    android:typeface="monospace"
    android:text="@string/hello" />
Run Code Online (Sandbox Code Playgroud)

变成这样:

<TextView
    style="@style/CodeFont"
    android:text="@string/hello" />
Run Code Online (Sandbox Code Playgroud)

通过定义xml主题文件:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="CodeFont" parent="@android:style/TextAppearance.Medium">
        <item name="android:layout_width">fill_parent</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:textColor">#00FF00</item>
        <item name="android:typeface">monospace</item>
    </style>
</resources>
Run Code Online (Sandbox Code Playgroud)

您还可以将样式应用于应用程序的所有活动:

<application android:theme="@style/CustomTheme">
Run Code Online (Sandbox Code Playgroud)

或者只是一项活动:

<activity android:theme="@android:style/Theme.Dialog">
Run Code Online (Sandbox Code Playgroud)