2012-02-25 344 views
0

我用這個佈局按鈕顏色(藍色):按鈕顏色沒有變化

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:state_pressed="true" > 
     <shape> 
      <solid 
       android:color="#449def" /> 
      <stroke 
       android:width="1dp" 
       android:color="#2f6699" /> 
      <corners 
       android:radius="3dp" /> 
      <padding 
       android:left="10dp" 
       android:top="10dp" 
       android:right="10dp" 
       android:bottom="10dp" /> 
     </shape> 
    </item> 
    <item> 
     <shape> 
      <gradient 
       android:startColor="#449def" 
       android:endColor="#2f6699" 
       android:angle="270" /> 
      <stroke 
       android:width="1dp" 
       android:color="#2f6699" /> 
      <corners 
       android:radius="4dp" /> 
      <padding 
       android:left="10dp" 
       android:top="10dp" 
       android:right="10dp" 
       android:bottom="10dp" /> 
     </shape> 
    </item> 
</selector> 

當我嘗試改變顏色,它不會改變它仍然是藍色的任何變化我做的。

我的strings.xml使用:

<style name="mybuttons"> 
    <item name="android:layout_width">fill_parent</item> 
    <item name="android:layout_height">wrap_content</item> 
    <item name="android:textColor">#ffffff</item> 
</style> 

下面是main.xml中的一部分:

<Button 
      android:id="@+id/select_c" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="@string/choose_c" 

      android:layout_marginTop="120dip" 
      android:background="@drawable/blue_button" 
      style="@style/mybuttons" 
       /> 
+0

繼'奧利C'回答你可能沒有設置的選擇背景,按鈕的背景,因爲我測試你的選擇並按照預期運行指定選擇項。 – Luksprog 2012-02-25 16:12:55

+0

@slukian:我更新了。問題是如果我改變顏色,它仍然是一樣的。 – George 2012-02-25 16:37:46

+0

我不認爲我明白你想達到的目標。你想要改變按鈕背景的顏色,選擇器的顏色(你在哪裏嘗試這樣做?)?我看到你爲這個按鈕設置了一些樣式,但是你沒有那種樣式的按鈕背景顏色,只是按鈕的文本。 – Luksprog 2012-02-25 17:01:25

回答

1

您應該android:state_pressedandroid:state_focused

1

你沒有提供足夠的信息來知道問題是什麼 - 哪來的XML佈局?

要使用選擇器drawable,您需要創建它(如您所做的那樣),然後將其應用於您的Button。我期望在那裏看到像background="@drawable/my_selector_drawable"這樣的屬性,將按鈕背景應用於佈局中的按鈕。

+0

:我更新了我的代碼。我正在應用背景。 – George 2012-02-25 16:36:50