我有一个导航抽屉活动,片段像往常一样用于导航抽屉的不同项目.导航抽屉的第一项中有一个标签布局.标签布局已使用viewpager实现.此viewpager中有一个地图.
我想做的就是打电话
SupportMapFragment mapFragment = (SupportMapFragment) getActivity().getSupportFragmentManager().findFragmentById(R.id.map);
Run Code Online (Sandbox Code Playgroud)
但mapFragment始终为null.
我花了2个多小时应用了很多方法,但我没能成功.
根据我的知识,这里的问题是这个.getActivity()方法返回导航抽屉活动.getSupportFragmentManager()返回附加到导航抽屉的片段.但地图不在那个片段中.Map位于视图分页器中的片段内.
谁能建议一种方法来实现这一目标?
我正在关注https://developers.google.com/identity/sign-in/android/sign-in,将google plus登录添加到我的Android应用中.
本文档建议采用以下方式添加红色Google plus登录按钮.
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestScopes(new Scope(Scopes.PLUS_LOGIN))
.requestEmail()
.build();
SignInButton signInButton = (SignInButton) findViewById(R.id.sign_in_button);
signInButton.setSize(SignInButton.SIZE_STANDARD);
signInButton.setScopes(gso.getScopeArray());
Run Code Online (Sandbox Code Playgroud)
但问题是现在不推荐使用setScopes方法.(https://developers.google.com/android/reference/com/google/android/gms/common/SignInButton)
setScopes(Scope[] scopes)
This method was deprecated. Setting scopes will no longer impact the branding.
Run Code Online (Sandbox Code Playgroud)
我也试过以下方法.
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this , this)
.addScope(new Scope(Scopes.PLUS_LOGIN))
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build();
Run Code Online (Sandbox Code Playgroud)
但红色的Google+按钮没有出现.如何添加以下按钮呢?