Emi*_*yan 30 android google-plus-one google-plus
我只是想知道是否还有在我的Android应用程序中添加Google +1按钮.我在Android Market上看过+1,所以我认为会有一些方法可以做到这一点.
Chi*_*hah 23
借助适用于Android的Google+平台,您现在可以在Android应用中集成原生+1按钮.
1)首先,您需要初始化的PlusClient对象在你的活动.
2)在布局中包含PlusOneButton:
<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" />
Run Code Online (Sandbox Code Playgroud)
3)将PlusOneButton分配给Activity.onCreate处理程序中的成员变量.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mPlusClient = new PlusClient(this, this, this);
mPlusOneButton = (PlusOneButton) findViewById(R.id.plus_one_button);
}
Run Code Online (Sandbox Code Playgroud)
4)每次活动在Activity.onResume处理程序中获得焦点时,刷新PlusOneButton的状态.
protected void onResume() {
super.onResume();
// Refresh the state of the +1 button each time the activity receives focus.
mPlusOneButton.initialize(mPlusClient, URL);
}
Run Code Online (Sandbox Code Playgroud)
有关详细信息,请参阅https://developers.google.com/+/mobile/android/#recommend_content_with_the_1_button
Jes*_*rix 10
接受的答案已经过时了......
XML:
<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" />
Run Code Online (Sandbox Code Playgroud)
活动:
// The request code must be 0 or greater.
private static final int PLUS_ONE_REQUEST_CODE = 0;
protected void onResume() {
super.onResume();
// Refresh the state of the +1 button each time the activity receives focus.
mPlusOneButton.initialize(URL, PLUS_ONE_REQUEST_CODE);
}
Run Code Online (Sandbox Code Playgroud)
甚至在那之前休闲这个链接:
https://developers.google.com/+/mobile/android/getting-started
| 归档时间: |
|
| 查看次数: |
16178 次 |
| 最近记录: |