在显示新视图之前,Facebook登录按钮在“注销"中更改其文本 [英] Facebook login button changes its text in 'log out' before new view is shown

查看:79
本文介绍了在显示新视图之前,Facebook登录按钮在“注销"中更改其文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Facebook SDK 4.0通过我的应用程序通过facebook实现了登录. 当用户单击Facebook登录按钮时,他导航到家庭活动并加载了新视图.问题是有一段时间,在facebook进程对话框消失之后并且在显示主视图之前,facebook登录按钮在注销"中更改了他的文本,并且用户可见.如何避免这种情况?

I implemented the login via facebook for my app using Facebook SDK 4.0. When the user clicks on facebook login button he navigates to home activity and a new view is loaded. The problem is that for a while, after the facebook process dialog disappears and before main view is shown, the facebook login button changes his text in 'Log out' and this is visible by the user. How can I avoid this?

这是我在片段登录中的代码:

This is my code in the fragment login:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState)
{
    View view = inflater.inflate(R.layout.frg_login, container, false);

    callbackManager = CallbackManager.Factory.create();

    fbLoginButton = (LoginButton) view.findViewById(R.id.fb_login_button);
    fbLoginButton.setReadPermissions("user_friends");
    fbLoginButton.setReadPermissions("public_profile");
    fbLoginButton.setFragment(this);
    fbLoginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
        @Override
        public void onSuccess(LoginResult loginResult) {
            GraphRequest request = GraphRequest.newMeRequest(
                    loginResult.getAccessToken(),
                    new GraphRequest.GraphJSONObjectCallback() {
                        @Override
                        public void onCompleted(
                                JSONObject object,
                                GraphResponse response) {
                            // Application code
                            Log.v("LoginActivity", response.toString());
                            session = new SessionManager(getActivity());
                            try{ String name = object.getString("name");
                                session.createLoginSession(name, true);
                                //Toast.makeText(getActivity(), "Login successful", Toast.LENGTH_SHORT).show();
                            }
                            catch (JSONException exe) {  }
                            }
                    });
            Bundle parameters = new Bundle();
            parameters.putString("fields", "id,name");
            request.setParameters(parameters);
            request.executeAsync();
        }

        @Override
        public void onCancel() {
            Toast.makeText(getActivity(), "Login canceled", Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onError(FacebookException exception) {
            Toast.makeText(getActivity(), "Login error", Toast.LENGTH_SHORT).show();
        }
    });

    return view;
}

在调用该片段的活动中:

And in the activity that calls the fragment:

if (currentAccessToken != null) {
                    navigatetoHomeActivity();
                }
public void navigatetoHomeActivity(){
        Intent homeIntent = new Intent(getActivity(),MainActivity.class);
        homeIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(homeIntent);
    }

感谢所有人

推荐答案

您可以通过在Facebook按钮XML中添加以下三行来将登录按钮和注销按钮的文本更改为相同:

You can change the text of your login and logout buttons to be the same by adding the following three lines to your Facebook button XML:

<com.facebook.login.widget.LoginButton
        ...

        ...
        xmlns:facebook="http://schemas.android.com/apk/res-auto"
        facebook:com_facebook_login_text="LOGIN"
        facebook:com_facebook_logout_text="LOGIN"/>

这篇关于在显示新视图之前,Facebook登录按钮在“注销"中更改其文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆