2012-07-03 23 views

回答

2

創建自定義按鈕爲:

步驟1:創建資源一個按鈕繪製形狀XML /繪製/ button_background.xml:

<?xml version=」1.0″ encoding=」UTF-8″?> 
<shape xmlns:android=」http://schemas.android.com/apk/res/android」> 
<solid android:color=」#F000″/> 
<stroke android:width=」1px」 android:color=」#BB000000″ /> 
<padding 
android:left=」10dp」 
android:top=」7dp」 
android:right=」10dp」 
android:bottom=」7dp」 
/> 
<corners 
android:bottomRightRadius=」5dp」 
android:bottomLeftRadius=」5dp」 
android:topLeftRadius=」5dp」 
android:topRightRadius=」5dp」 
/> 
<gradient 
android:angle=」90″ 
android:startColor=」#777″ 
android:centerColor=」#777″ 
android:endColor=」#BBB」 
android:type=」linear」 
/> 

</shape> 

第2步:添加在您的主要按鈕xml佈局爲:

<Button android:id="@+id/btn" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Facebook" 
     android:drawableLeft="@drawable/leftimg" 
     android:drawableRight="@drawable/rightimg" 
     android:padding="15dip" 
     android:background="@drawable/button_background"/> 
+0

這裏'android:drawableRight =「@ drawable/rightimg」'doesnot make image in the right right – MBMJ

+0

@SidratulMuntaha:then remove padding android:right =佈局中的「10dp」 –

0

,你可以在你的按鈕做android:drawableLeft="@drawable/your_icon"

+0

你的意思是我需要在其背景中實現一個圖像? – MBMJ

+0

是的,對於你也可以給android:drawableRight =「@ drawable/arrow」 –

相關問題