2013-05-30 86 views
12

默認的Facebook LoginButton對象和谷歌簽到按鈕對象有完全不同的表現,他們並不在我的現有佈局結合在一起。據我所知,這些對象都沒有的資產,我可以修改不改變庫本身(在那裏我會承擔這些組件也開源)谷歌Android登入與Facebook登錄按鈕看起來完全不同

人們如何面對呢?我看到了那些使用自己的自定義按鈕的應用程序都有登錄選項,但在我的實現中,我使用的是那些給定對象,在點擊時自動調用它們各自的庫。

我當然可以下潛更深,但我覺得我重新發明不那麼明顯的車輪,如果我這樣做,

<com.google.android.gms.common.SignInButton 
       android:id="@+id/sign_in_button" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" /> 

這個對象不是那麼明顯的一個按鈕,我沒有然後檢查是否真的是一個按鈕。

我需要使用不同的資產,同時爲Google+和Facebook登錄按鈕。

我有什麼

一個Android例如我喜歡(聽歌APP)

編輯: 後,一些很簡單的佈局調整,這是結果(以風景模式,只是爲了說明問題)

這些按鈕仍然非常不同,我需要一個不同的資產,仍可以訪問正確的方法。我有點像Facebook這樣做,感謝這些例子,但谷歌登錄現在對我來說很神祕

+0

你試過設置layout_width屬性一個實際的寬度而不是wrap_content? –

+0

現在好了,我覺得認知疏忽,@PatrickEvans,也許我可以把它放在一個FrameLayout並設置按鈕match_parent – CQM

+0

@PatrickEvans好吧,所以我讓他們排隊'match_parent'參數,但他們仍然看起來完全不同。管道|徽標和其他按鈕之間的位置在不同的地方,Facebook按鈕在橫向模式下看起來很糟糕......我想知道其他人如何處理此問題 – CQM

回答

11

要改變Facebook上的按鈕使用文本:

fb:login_text="Put your login text here" 
fb:logout_text="Put your logout text here" 

你也需要把它添加到按鈕:

xmlns:fb="http://schemas.android.com/apk/res-auto" 

像這樣:

<com.facebook.widget.LoginButton 
     xmlns:fb="http://schemas.android.com/apk/res-auto" 
     android:id="@+id/login_button" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_horizontal" 
     android:layout_marginTop="30dp" 
     android:layout_marginBottom="0dp" 
     fb:login_text="Sign in with Facebook" 
     /> 
1

這些按鈕沒有完全相同的樣式 - 角落上的不同曲線和使用放下陰影。所以它不可能讓它們看起來完全一樣。我能得到的最接近的是使一個垂直線性佈局215dip的精確的寬度 - 並設置按鈕的寬度要match_parent:

enter image description here

這用於以下layout.xml:

<LinearLayout 
    android:layout_width="215dip" 
    android:layout_height="wrap_content" 
    android:layout_centerHorizontal="true" 
    android:orientation="vertical" > 

<com.google.android.gms.common.SignInButton 
    android:id="@+id/sign_in_button" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" /> 

<com.facebook.widget.LoginButton 
    android:id="@+id/authButton" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" /> 

</LinearLayout> 

使用Google+按鈕,您可以簡單地使用自己的資產 - com.google.android.gms.common.SignInButton的行爲與android.widget.Button的行爲相同,並以正常方式註冊onClick處理程序。只是一定要效仿谷歌的品牌準則,當你創建你的資產:

https://developers.google.com/+/branding-guidelines

然而要注意的Google+按鈕的功能提供,如果你在幾種語言實現自己的按鈕,您將需要創建自己的翻譯。

+10

我喜歡一個按鈕說如何登錄和其他登錄;) –

+0

檢查了這我怎麼定製他們看起來確切。 http://karunadheera.com/index.php/archives/160 – prageeth

+0

鏈接已死,您可以轉發嗎? –

3

嘗試此: 將此方法加入您的活動:

protected void setGooglePlusButtonText(SignInButton signInButton, String buttonText) { 
     for (int i = 0; i < signInButton.getChildCount(); i++) { 
      View v = signInButton.getChildAt(i); 

      if (v instanceof TextView) { 
       TextView tv = (TextView) v; 
       tv.setTextSize(15); 
       tv.setTypeface(null, Typeface.NORMAL); 
       tv.setInputType(InputType.TYPE_TEXT_FLAG_CAP_WORDS); 
       tv.setText(buttonText); 
       return; 
      } 
     } 
    } 

添加按照onCreateMethod (其中已初始化ID用)線:

setGooglePlusButtonText(btnSignIn, getString(R.string.common_signin_button_text_long)); 
0

隨着最新的SDK,這兩個按鈕看起來相似。代碼和結果在下面提到。

步驟1:的build.gradle

編譯 'com.facebook.android:facebook-android-sdk:4.6.0'

編譯「com.google.android.gms:播放 - 服務:7.5.0'

第2步:myActivity.xml

<com.google.android.gms.common.SignInButton 
android:id="@+id/sign_in_button" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" /> 

<com.facebook.login.widget.LoginButton 
android:id="@+id/login_button" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:layout_gravity="center_vertical"/> 

步驟3:結果 enter image description here 第4步:更新了最新的GCM的build.gradle

compile 'com.facebook.android:facebook-android-sdk:4.6.0' 
compile 'com.google.android.gms:play-services:8.4.0' 

第5步:結果

enter image description here

+0

隨着新的SDKs變得令人厭惡,所以他們讓我們打破了他們品牌的「規則」...... – Galya