2016-09-20 120 views
0

誰可以幫我風格按鈕?我如何改變按鈕的風格,我沒有角度問題,我的意思是,爲什麼我有默認的按鈕樣式。 這是我的代碼,並顯示問題按鈕的風格Android

Angels1

Angles2

Button style="@style/gradient_button" 

風格 - gradient_button

<style name="button_common"> 
<item name="android:layout_height">wrap_content</item> 
<item name="android:layout_width">wrap_content</item> 
<item name="android:textColor">#ffffff</item> 
<item name="android:textSize">14sp</item> 
</style> 
    <style name="gradient_button" parent="@style/button_common"> 
     <item name="android:background">@drawable/button_grad</item> 
    </style> 

和文件button_grad

<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item 
     android:state_enabled="true" 
     android:state_pressed="false" 
     android:drawable="@drawable/b59" /> 
    <item 
     android:state_enabled="true" 
     android:state_pressed="true" 
     android:drawable="@drawable/y59" /> 
    <item 
     android:state_enabled="false" 
     android:drawable="@drawable/b59" /> 
</selector> 

b59和y59這些是帶有9個補丁的圖像。

回答

0

關於你的角度的問題錯誤是關於你的圖像或關於9補丁。

你可以寫按鈕的樣式在繪製文件夾:

style_button.xml

<style name="button_common"> 
<item name="android:layout_height">wrap_content</item> 
<item name="android:layout_width">wrap_content</item> 
<item name="android:textColor">#ffffff</item> 
<item name="android:textSize">14sp</item> 
</style> 

selector.xml在您繪製的文件夾:

<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item 
     android:state_enabled="true" 
     android:state_pressed="false" 
     android:drawable="@drawable/b59" /> 
    <item 
     android:state_enabled="true" 
     android:state_pressed="true" 
     android:drawable="@drawable/y59" /> 
    <item 
     android:state_enabled="false" 
     android:drawable="@drawable/b59" /> 
</selector> 

將該樣式應用於您的按鈕:

<Button 
       android:id="@+id/btn" 
       style="@style/style_button" 
       android:layout_centerVertical="true" 
       android:background="@drawable/selector" 
       android:drawablePadding="10dp" 
       android:text="btnText" /> 
+0

我試過了,但天使們仍然遇到了問題。你能看到圖1和圖2,我不知道。也許這是問題背景默認按鈕(材料設計) –

+0

也許問題是關於您的圖像和約9補丁 – Carlo

+0

哦,我想,你確定。謝謝你 –