为什么我的应用程序中的颜色没有被覆盖?

时间:2017-06-16 20:50:46

标签: android xamarin.android android-button

为什么我的按钮颜色没有变化?

<application android:label="Sales Plus" android:icon="@drawable/Icon" 
 android:theme="@style/AppTheme"></application>

App主题定义为:

<style name="AppTheme.Base" parent="Theme.AppCompat.Light">


</style>
  <!-- inherit from the AppCompat theme -->
  <style name="AppTheme" parent="AppTheme.Base">
    <!-- Color overrides -->
    <item name="colorPrimary">@color/primary</item>
    <item name="colorPrimaryDark">@color/primary_dark</item>
    <item name="colorAccent">@color/accent</item>
    <!-- Background Color Override -->
    <item name="android:windowBackground">@color/window_background</item>
  </style>

创建主题

<style name="ButtonTheme" parent="Widget.AppCompat.Button">
    <item name="colorButtonNormal">@color/primary</item>
    <item name="colorControlHighlight">@color/accent</item>
  </style>

ButtonSM的样式:

<style name="ButtonSm" parent="Widget.AppCompat.Button.Colored">
    <item name="android:layout_width">wrap_content</item>
    <item name="android:layout_height">wrap_content</item>
</style>

应用主题:

<Button
      android:text="@string/about"
      android:id="@+id/btnAbout"
      style="@style/ButtonSm"
      android:theme="@style/ButtonTheme"
      />

但是,出现的按钮颜色是默认的绿色。 使用Xamarin.Android.Support.v7.AppCompat和Android Framework 7.1版(API lvl 25)。另外,在Lollipop上测试......

我尝试将ButtonTheme父级更改为ThemeOverlay以及Widget.AppCompat.Button.Colored

我已经查看了Coloring Buttons in Android with Material Design and AppCompat

1 个答案:

答案 0 :(得分:0)

有些样式被应用于axml中另一个实际上并不存在的元素。删除它们后,应用的样式没有问题。

我在应用主题(值v-21)中声明了我的主色和强调色,这是在manifest.xml中应用的。 AppCompat主题在整个应用程序中自动将重音颜色应用于我的按钮。

我希望这篇文章对其他人有所帮助。