2017-04-19 127 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>