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

标签 android

我正在开发一个 Android 应用程序,我想更改应用程序的颜色和主题。我该怎么做?

最佳答案

Dev guide explains how to apply themes and styles.

这个:

<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textColor="#00FF00"
    android:typeface="monospace"
    android:text="@string/hello" />

变成这样:

<TextView
    style="@style/CodeFont"
    android:text="@string/hello" />

通过定义一个 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>

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

<application android:theme="@style/CustomTheme">

或者只是一项 Activity :

<activity android:theme="@android:style/Theme.Dialog">

关于android - 如何更改 Android 应用程序的主题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4189272/

相关文章:

android - 动态设置 React Native <Image/> 的 uri

android - 应该定义“layout_height”属性

java - JPG 与 Android 上的 WebP 性能对比

android - 将 SharedPreferences 文件保存到自定义目录或获取默认 SharedPreferences 目录

Android Studio 不会导入 SVG Vector 的所有部分

android - 将 fragment 的 HashMap 传递给 bundle

android - flv 到 mp4 转换

java - 让Java中的方法返回在内部类中初始化的变量

Android:oauth.signpost.exception.OAuthCommunicationException:与服务提供商的通信失败:没有对等证书

android - 如何在辅助工具栏上为 SearchView 设置 MenuItemClickListener