2015-10-25 18 views
0

我正在學習如何在Android中創建良好的用戶界面,並且我想知道如何製作此類按鈕或類似按鈕。任何幫助將不勝感激。如何在Android中自定義一個按鈕,看起來如下圖所示,請參閱圖像

我一直在用UI掙扎,我不是一個設計師,但會喜歡慢慢地學習。這是我到目前爲止所嘗試的,我想知道如何添加角落。在此先感謝

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > 
    <corners 
     android:radius="14dp" 
     /> 
    <gradient 
     android:angle="45" 
     android:centerX="55%" 
     android:centerColor="#FFE9B3" 
     android:startColor="#FFC627" 
     android:endColor="#FFD152" 
     android:type="linear" 
     /> 
    <padding 
     android:left="4dp" 
     android:top="2dp" 
     android:right="4dp" 
     android:bottom="2dp" 
     /> 
    <size 
     android:width="270dp" 
     android:height="60dp" 
     /> 
    <stroke 
     android:width="7dp" 
     android:color="#FFFFFF" 
     /> 
</shape> 

見圖片

enter image description here

回答

2

你可以使用層列表像休耕:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item> 
     <shape> 
      <solid android:color="#b0a079"/> 
      <corners android:radius="20dp"/> 
     </shape> 
    </item> 

    <item android:bottom="5dp"> 
     <shape> 
      <solid android:color="#efefef"/> 
      <corners android:radius="20dp"/> 
     </shape> 
    </item> 

    <item android:bottom="15dp"> 
     <shape> 
      <solid android:color="#df9931"/> 
      <corners android:radius="20dp"/> 
     </shape> 
    </item> 

    <item android:bottom="25dp"> 
     <shape> 
      <solid android:color="#ffc627"/> 
      <corners android:radius="20dp"/> 
     </shape> 
    </item> 
</layer-list> 

更新: 爲 「EASY」(按鈕文本)您可以更改自定義字體(字體)的按鈕字體,與預覽圖像相似。找到你的自定義字體,在資產複製字體和使用它像下面的代碼:

Button btnEasy =(Button)findViewById(R.id.btn_easy); 
Typeface typeFace = Typeface.createFromAsset(getAssets(),"your_custom_font_name.ttf"); 
btnEasy.setTypeface(typeFace); 

我建議創建一個從資產的字樣一次的時間,如果你想在你的應用程序中使用它在其他地方存放在單獨的對象(它只是顯示用例)

+0

非常感謝,我很感激。 –

+0

嘿按鈕上的文字有什麼方法可以讓它變得類似?提前致謝。 –

+1

@Mia歡迎您,回覆已更新。 –

相關問題