2017-06-16 32 views
0

爲什麼我的按鈕顏色不變?爲什麼我的應用程序中的顏色沒有被覆蓋?

<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)。此外,測試的棒棒糖......

我試圖改變ButtonTheme父ThemeOverlay以及Widget.AppCompat.Button.Colored

我已經看着Coloring Buttons in Android with Material Design and AppCompat

+0

什麼風格是@ style/ButtonSm? –

+0

你可以請你顯示你的風格'ButtonSm'的代碼,以便我們可以進行測試嗎? –

+0

剛剛添加,讓我知道,如果任何其他片段可以幫助。 –

回答

0

有風格被應用到實際上並不存在的axml中的另一個元素。刪除它們後,樣式應用沒有問題。

我在應用於manifest.xml的App Theme(值爲v-21)中聲明瞭我的主色和重點色。在整個應用程序中,AppCompat主題自動將重音顏色應用於我的按鈕。

我希望這篇文章對別人有幫助。

相關問題