在Android应用中添加Google +1按钮 [英] Adding a Google +1 button in Android App
问题描述
我只是想知道是否在我的Android应用程序中添加了Google +1按钮. 我在Android Market上看到了+1,所以我认为会有一些方法可以做到这一点.
I was just wondering if there was anyway to add a Google +1 button inside my Android app. I have seen a +1 on the Android Market so I would think there would be some way to do this.
推荐答案
借助适用于Android的Google+平台,您现在可以在Android应用中集成本机+1按钮.
With the Google+ platform for Android, you are now able to integrate a native +1 button in your Android app.
1)您首先需要初始化中的PlusClient
对象您的活动.
1) You first need to initialize the PlusClient
object in your Activity.
2)在您的布局中包含PlusOneButton:
2) Include the PlusOneButton in your layout:
<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" />
3)将PlusOneButton分配给Activity.onCreate处理程序中的成员变量.
3) Assign the PlusOneButton to a member variable in your Activity.onCreate handler.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mPlusClient = new PlusClient(this, this, this);
mPlusOneButton = (PlusOneButton) findViewById(R.id.plus_one_button);
}
4)每当活动在Activity.onResume处理程序中获得焦点时,刷新PlusOneButton的状态.
4) Refresh the PlusOneButton's state each time the activity receives focus in your Activity.onResume handler.
protected void onResume() {
super.onResume();
// Refresh the state of the +1 button each time the activity receives focus.
mPlusOneButton.initialize(mPlusClient, URL);
}
有关更多信息,请参见 https://developers.google.com/+/移动/android/#recommend_content_with_the_1_button
For more information, see https://developers.google.com/+/mobile/android/#recommend_content_with_the_1_button
这篇关于在Android应用中添加Google +1按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!