2011-07-13 138 views
5

我想製作一個帶形狀的自定義按鈕,如何做到這一點?如何使用xml或使用java更改按鈕的形狀?

+1

「想讓自定義按鈕形狀」不是一個可以理解的描述。詳細說明問題。 –

+0

看到這個:[自定義按鈕風格和主題在Android](http://blog.androgames.net/40/custom-button-style-and-theme/) –

回答

16

這是橢圓形狀的示例按鈕。gradient表示開始n結束顏色與角度。角落爲橢圓形..試試這個..提起這個xml的名字在按鈕背景android:background="@drawable/sample"。保存xml在可繪製

<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle"> 
    <gradient 
     android:startColor="#302226" 
     android:endColor="#6D7B8D" 
     android:angle="45"/> 
    <padding android:left="6dp" 
     android:top="6dp" 
     android:right="6dp" 
     android:bottom="6dp" /> 
    <corners android:radius="30dp" /> 

</shape> 

還要檢查這個link自定義按鈕。

+0

你好,Hussain它工作正常Thk你 – suresh

+0

嗨sureshpathi ,如果答案對你有幫助,那麼就考慮接受答案,另見http://meta.stackexchange.com/questions/16721/how-does-accept-rate-work。 – Hussain

0

另一種方法來找到按鈕,在不同的形狀XML

使用的ImageButton作爲

 <ImageButton 
      android:id="@+id/imageButton1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/shape_oval" /> 

Shape_oval是我們可以從谷歌serching或繪製我們自己的油漆或Photoshop的圖像。