13

Facebook Sdk for Android は、XML から渡された login_text および logout_text 値を受け取りません。無視するだけです。このボタンのカスタマイズを使用するドキュメント/例は地球上にはありません。

<com.facebook.widget.LoginButton
    xmlns:fb="http://schemas.android.com/apk/res-auto"
    android:id="@+id/connectWithFbButton"
    style="@style/com_facebook_loginview_default_style"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:layout_gravity="center_horizontal"
    android:text="@string/connect_with_facebook"
    fb:login_text="@string/connect_with_facebook"
    fb:logout_text="Connecting with facebook" />

常にログインまたはログアウトと表示されます。このプロパティを使用するにはどうすればよいですか? LoginButton コードを使用してデバッグを試みましたが、無駄でした。LoginButton() のコンストラクタを通過しないため、カスタム パラメータを解析できません。

誰かがこの問題に直面しましたか?

4

6 に答える 6

5

あなたの最初の解決策は正しいです。スタイル属性を定義したため、機能しませんでした:

style="@style/com_facebook_loginview_default_style"

LoginButton ソースコードから:

public LoginButton(Context context, AttributeSet attrs) {
    super(context, attrs);

    if (attrs.getStyleAttribute() == 0) {
        do stuff ...
    }
}

そのため、「style」属性を未定義のままにしておくと、定義済みの属性「login_text」のみが参照されます。

于 2013-03-14T19:03:50.623 に答える
2

ガブリエルは当たりです。これを修正するには、Facebook SDK の LoginButton.java に移動し、parseAttributes 呼び出しを移動します。

parseAttributes(attrs)

常に実行されるようにします。

メソッド全体は次のようになります。

public LoginButton(Context context, AttributeSet attrs) {
    super(context, attrs);

    if (attrs.getStyleAttribute() == 0) {
            // apparently there's no method of setting a default style in xml,
            // so in case the users do not explicitly specify a style, we need
            // to use sensible defaults.
            this.setTextColor(getResources().getColor(R.color.com_facebook_loginview_text_color));
            this.setTextSize(TypedValue.COMPLEX_UNIT_PX,
                    getResources().getDimension(R.dimen.com_facebook_loginview_text_size));
            this.setPadding(getResources().getDimensionPixelSize(R.dimen.com_facebook_loginview_padding_left),
                    getResources().getDimensionPixelSize(R.dimen.com_facebook_loginview_padding_top),
                    getResources().getDimensionPixelSize(R.dimen.com_facebook_loginview_padding_right),
                    getResources().getDimensionPixelSize(R.dimen.com_facebook_loginview_padding_bottom));
            this.setWidth(getResources().getDimensionPixelSize(R.dimen.com_facebook_loginview_width));
            this.setHeight(getResources().getDimensionPixelSize(R.dimen.com_facebook_loginview_height));
            this.setGravity(Gravity.CENTER);

        if(isInEditMode()) {
            // cannot use a drawable in edit mode, so setting the background color instead
            // of a background resource.
            this.setBackgroundColor(getResources().getColor(R.color.com_facebook_blue));
            // hardcoding in edit mode as getResources().getString() doesn't seem to work in IntelliJ
            loginText = "Log in";
        } else {
            this.setBackgroundResource(R.drawable.com_facebook_loginbutton_blue);
            initializeActiveSessionWithCachedToken(context);
        }
    } 
    parseAttributes(attrs);
}

style と login_text の両方が現在検討中です。私にとってはうまくいきます。

于 2013-05-24T09:44:59.590 に答える
1

FacebookSDK ソースのテキストを変更するだけで済みました。

ログイン文字列は次のcom_facebook_loginview_log_in_button場所にあります。FacebookSDK/res/values/strings.xml

于 2013-02-28T21:46:32.727 に答える
0

これらのソリューションの多くを試しましたが、何も機能しませんでした。最終的には次のようになりました。

Locale loc = Locale.FRENCH;
loginButton = (LoginButton)findViewById(R.id.fb_login_button);
loginButton.setTextLocale(loc);

これにより、テキストが設定したロケールに変更され、確認ダイアログも少なくとも必要なものに変更されます。

お役に立てれば。

于 2015-07-03T11:58:33.720 に答える