2016-02-13 56 views
0

我設置colorButtonNormal在我styles.xml像這樣:colorButtonNormal沒有填滿整個按鈕

<style name="AppBaseTheme" parent="Theme.AppCompat.Light.NoActionBar"> 
    ... 
    <item name="colorButtonNormal">#33cc33</item> 
</style> 

然而,從這個屬性的背景不填按鈕的整個空間。

我有兩個按鈕。 One使用colorButtonNormal和其他使用Android的背景設置爲相同的顏色:背景:

 <Button 
      android:id="@+id/afs_login_button" 
      android:layout_width="fill_parent" 
      android:layout_height="55dp" 
      android:layout_marginBottom="10dp" 
      android:textAllCaps="false" 
      android:text="Button" 
      android:textColor="#FFF" /> 

     <Button 
      android:layout_width="fill_parent" 
      android:layout_height="55dp" 
      android:background="#33cc33" 
      android:id="@+id/guest_login" 
      android:text="Button" 
      android:textColor="#FFF" /> 

而下面是結果在Android Studio的預覽窗格:

enter image description here

,你可以看,藍色輪廓是按鈕,綠色背景不佔據整個空間。但是,如果我專門設置了android:background,它會填充整個空間。任何想法爲什麼?

回答

0

與默認按鈕一起使用的背景可繪製被填充。點擊區域大於實際(可見)按鈕大小,這就是你在UI檢查器中看到的。

設置一種顏色作爲背景只會填補按鈕的整個範圍,使似乎更大的按鈕。點擊區域仍然相同。這是因爲顏色轉換爲ColorDrawable

您可以使用tint更改可繪製的顏色—這可以讓您更改顏色,但保留按鈕樣式。

+0

不幸的是,這產生了與使用colorButtonNormal – user1282637

+0

@ user1282637相同的結果你是否真的想讓默認按鈕被單色着色並像第二個例子那樣填充整個空間? –

+0

我希望它具有與使用colorButtonNormal相同的行爲,但顏色填充背景。即它保持它的選擇器狀態和棒棒糖+上的漣漪效應(這就是爲什麼我不能僅僅使用android:background) – user1282637