我想为我的 google plus 按钮创建自定义布局,有什么想法吗?我尝试调用 google plus 按钮的 OnClickEvent (这不起作用),并且尝试更改背景图像。源代码:
<com.google.android.gms.plus.PlusOneButton
xmlns:plus="http://schemas.android.com/apk/lib/com.google.android.gms.plus"
android:id="@+id/plus_one_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
plus:size="standard"
plus:annotation="inline"/>
holder.mPlusOneButton = (PlusOneButton) holder.content.findViewById(R.id.plus_one_button);
holder.mPlusOneButton.initialize("http://www.xxx.xx/", 0);
- 将自定义按钮添加到您的布局中
- Set
OnClickListener
到您的自定义按钮
- Use the
PlusClient
如上所述here https://developers.google.com/+/mobile/android/getting-started#step_3_initialize_the_plusclient处理登录程序
例如,我可以提供我的控制器类来处理 Google Plus 登录:
public class GooglePlusLoginController implements GooglePlayServicesClient.ConnectionCallbacks, GooglePlayServicesClient.OnConnectionFailedListener {
public static final int REQUEST_CODE_SIGN_IN = 100;
private PlusClient googlePlusClient;
private ConnectionResult connectionResult;
private Activity activity;
public GooglePlusLoginController(Activity activity) {
this.activity = activity;
googlePlusClient = new PlusClient.Builder(activity, this, this)
.setActions("http://schemas.google.com/AddActivity")
.setScopes(Scopes.PLUS_LOGIN) // Space separated list of scopes
.build();
googlePlusClient.connect();
}
// call this method in your click handler
public void login() {
try {
connectionResult.startResolutionForResult(activity, REQUEST_CODE_SIGN_IN);
} catch (IntentSender.SendIntentException e) {
googlePlusClient.connect();
}
}
// call this method in your activity's onActivityResult
public void onActivityResult() {
if(!googlePlusClient.isConnected() && !googlePlusClient.isConnecting()) {
googlePlusClient.connect();
}
}
@Override
public void onConnected(Bundle bundle) {
// connected, you can now get user's data from
// googlePlusClient.getCurrentPerson()
}
@Override
public void onDisconnected() {
}
@Override
public void onConnectionFailed(ConnectionResult result) {
connectionResult = result;
}
private void logout() {
if(googlePlusClient.isConnected()) {
googlePlusClient.clearDefaultAccount();
googlePlusClient.disconnect();
googlePlusClient.connect();
}
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)