2011-07-13 140 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的图像。