2013-05-11 39 views

Trả lời

78

tôi đã kết thúc trọng các văn bản là chuỗi rỗng và sau đó xác định setBackgroundResource của nút để tôi hình ảnh (không cần đăng nhập/đăng xuất chức năng text động)

<com.facebook.widget.LoginButton 
     xmlns:fb="http://schemas.android.com/apk/res-auto" 
     android:id="@+id/login_button" 
     android:layout_width="249dp" 
     android:layout_height="45dp" 
     android:layout_above="@+id/textView1" 
     android:layout_centerHorizontal="true" 
     android:layout_gravity="center_horizontal" 
     android:layout_marginBottom="30dp" 
     android:layout_marginTop="30dp" 
     android:contentDescription="@string/login_desc" 
     android:scaleType="centerInside" 
     fb:login_text="" 
     fb:logout_text="" /> 

Và trong mã tôi đã xác định tài nguyên nền:

final LoginButton button = (LoginButton) findViewById(R.id.login_button); 
button.setBackgroundResource(R.drawable.facebook); 

Loại giải pháp khác, nhưng tôi ưa thích điều này hơn là thay đổi mã SDK của Facebook (mặc dù nó rất thẳng về phía trước) và lo lắng về việc cập nhật mỗi khi tôi cập nhật phiên bản của họ.

+1

Chỉ cần tò mò: bạn đã tìm tài liệu/trợ giúp về 'fb: login_text' và các thuộc tính XML như vậy ở đâu? Đó là chính xác những gì tôi đang tìm kiếm nhưng không có ý tưởng làm thế nào mọi người vấp phải nó. –

+3

Facebook sdk là mã nguồn mở. Kiểm tra res/values ​​/ attrs.xml của nó –

+3

Nó vẫn hiển thị biểu tượng 'f' của Facebook, cách xóa nó? – SkyWalker

9

có nếu bạn muốn thay đổi cả văn bản và hình ảnh, sau đó viết mã bên dưới.

authButton = (LoginButton) view.findViewById(R.id.authButton); 
authButton.setBackgroundResource(R.drawable.icon); 
authButton.setText("Login"); 
authButton.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);` 
1

Một cách khác

loginButton = (LoginButton) findViewById(R.id.fb_login_button); 
loginButton.setVisibility(View.GONE); 




ImageView ivFbCustomButton = (ImageView) findViewById(R.id.iv_fb_custom_button); 
ivFbCustomButton.setOnClickListener(new View.OnClickListener() { 
    @Override 
    public void onClick(View v) { 
     com.facebook.login.widget.LoginButton btn = new com.facebook.login.widget.LoginButton(FacebookActivity.this); 
     btn.performClick(); 
    } 
}); 

Lưu ý:

Bạn phải viết mã cho hai nút trong tập tin XML. Một là dành cho nút facebook mặc định (Chúng tôi đang ẩn nó ở bước ban đầu). Thứ hai là dành cho nút tùy chỉnh

Các vấn đề liên quan