2017-04-19 129 views
0

我想在我的應用程序中添加'用Google登錄'功能。我正在使用以下代碼添加谷歌登錄按鈕圓角谷歌登錄按鈕 - android

<com.google.android.gms.common.SignInButton 
    android:id="@+id/btn_google_signin" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="24dp" 
    android:background="?attr/selectableItemBackground" 
    android:elevation="2dp"></com.google.android.gms.common.SignInButton> 

這是渲染一個矩形按鈕。但我想要圓角按鈕。有什麼方法可以用圓角來定製這個按鈕嗎?

P.S. - 我不想自定義正常按鈕。我特別在尋找Google SignInButton。如果你知道這一點,請回復。

+0

你需要有drawble背景的.. –

+0

檢查這個職位的答案 http://stackoverflow.com/questions/6054562/how-to-make-一角的按鈕輪 –

+0

這是正常的按鈕,我知道這一點。非常特定的谷歌登錄按鈕。 –

回答

0

round_style.xml在drawable文件夾中。

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android" > 
<item android:state_pressed="true" > 
    <shape android:shape="rectangle" > 
     <corners android:radius="3dip" /> 
     <stroke android:width="1dip" android:color="#5e7974" /> 
     <gradient android:angle="-90" android:startColor="#345953" android:endColor="#689a92" />    
    </shape> 
</item> 
<item android:state_focused="true"> 
    <shape android:shape="rectangle" > 
     <corners android:radius="3dip" /> 
     <stroke android:width="1dip" android:color="#5e7974" /> 
     <solid android:color="#58857e"/>  
    </shape> 
</item> 
<item > 
    <shape android:shape="rectangle" > 
     <corners android:radius="3dip" /> 
     <stroke android:width="1dip" android:color="#5e7974" /> 
     <gradient android:angle="-90" android:startColor="#8dbab3" android:endColor="#58857e" />    
    </shape> 
</item> 
</selector> 

OR

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
<item> 
    <shape android:shape="rectangle"> 
     <solid android:color="#DEB887"/> 
     <stroke android:color="#8A2BE2" android:width="2dp" /> 
     <!--corners allow us to make the rounded corners button--> 
     <corners android:radius="15dp" /> 
    </shape> 
</item> 
</selector> 

現在使用

<com.google.android.gms.common.SignInButton 
    android:id="@+id/btn_google_signin" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="24dp" 
    android:background="@drawable/round_style" 
    android:elevation="2dp"></com.google.android.gms.common.SignInButton> 
+0

與您的解決方案,圓形背景在後面,按鈕出現在圓形背景 –

0

您可以使用卡片視圖。並把SignInButton到CardView這樣的:

<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto"     
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent"  
    android:layout_marginBottom="4dp"         
    android:layout_marginRight="4dp"         
    android:layout_marginTop="4dp"         
    app:cardCornerRadius="4dp" 
    app:cardElevation="2dp"> 

    <com.google.android.gms.common.SignInButton 
    android:id="@+id/btn_google_signin" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="24dp" 
    android:background="?attr/selectableItemBackground" 
    android:elevation="2dp"></com.google.android.gms.common.SignInButton> 

</android.support.v7.widget.CardView>