【问题标题】:How to change the accent color on my Android app from blue to something else如何将我的 Android 应用程序上的强调色从蓝色更改为其他颜色
【发布时间】:2012-07-31 15:17:24
【问题描述】:

我想要做的就是更改我的 android 应用程序的强调色,但我很难弄清楚如何做到这一点。 android 现在默认是蓝色的,但我想让它变成橙色。

强调色是指导航选项卡的强调色、点击列表时突出显示的颜色、弹出对话框中的强调色等。

如果这很重要,我正在使用 actionbarsherlock。

这是一张图片。我想在整个应用程序中更改蓝色口音的颜色:

【问题讨论】:

    标签: android colors tabs actionbarsherlock diacritics


    【解决方案1】:

    你问这个问题已经有一段时间了,但现在谷歌已经发布了一个新的 AppCompat 版本,你可以很简单地做你想做的事情。我给你的答案灵感来自android developer blog support library 2.2.1

    1. 将支持库添加到您的项目中(我假设您使用的是 Android Studio)。

      为此,将这些行添加到 app.graddle 文件中(假设您的模块名为 app)。

      dependencies {
          compile 'com.android.support:appcompat-v7:22.2.0'
      }
      

    1. 设置应用程序的主题

      这些行将被添加到您的styles.xml 文件中。如您所见,这种风格有一些项目。如果您想知道它们对应的元素,请查看customize android status bar with material

      colorAccent 是您首先要更改的颜色。

      <!-- Base application theme. -->
      <style name="AppTheme" parent="Theme.AppCompat">
          <item name="colorPrimary">@color/primary</item>
          <item name="colorPrimaryDark">@color/primaryDark</item>
          <item name="colorAccent">@color/accent</item>
          <item name="android:textColorPrimary">@color/textColorPrimary</item>
          <item name="android:windowBackground">@color/windowBackground</item>
          <item name="android:navigationBarColor">@color/navigationBarColor</item>
      </style>
      

      您还需要在 Android 清单中设置应用程序主题

      <application
          android:theme="@style/AppTheme" >
      
          ...
      
      </application>
      

    1. 在您的课程中从 Activity / ActionBarActivity 更改为 AppCompatActivity

      public class MainActivity extends AppCompatActivity
      {
           ....
      }
      

      由于 AppCompatActivity,您可能需要更改一些方法。查看第一个链接中的视频以更好地理解:)


    1. 将您的小部件更改为 AppCompat 的小部件

      <LineareLayout
          xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:tools="http://schemas.android.com/tools"
          android:layout_width="match_parent"
          android:layout_height="match_parent">
      
          <android.support.v7.widget.AppCompatTextView
              android:id="@+id/text"
              android:text="@string/hello_world"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content" />
      
          <android.support.v7.widget.AppCompatButton
              android:id="@+id/btn_start"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="@string/btn_start" />
      
      </RelativeLayout>
      

    等等!大功告成 :) 现在您可以轻松更改重点颜色了。

    【讨论】:

      【解决方案2】:

      您将要使用状态布局列表。

      http://developer.android.com/reference/android/content/res/ColorStateList.html

      您可能需要为每个将具有新的默认选定颜色的小部件制作其中一个。

      【讨论】:

      • 我不想制作新的选定颜色,我已经使用这种工具来创建自定义按钮。但我只是想改变强调色,让我在我的问题中添加一个屏幕截图以便更好地解释
      • 看起来那个人试图做我想做的事,但从未解决
      • 你看过他推荐给他的样式样本吗?您也可以尝试他的原始解决方案,因为其他人可能只是做错了什么。
      • 看看这个问题的第二个答案:stackoverflow.com/questions/13257219/…
      猜你喜欢
      • 2012-10-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-16
      • 1970-01-01
      • 2012-09-30
      • 1970-01-01
      相关资源
      最近更新 更多