我整合了Google+按钮,我在我的应用中看到了它,但它是“灰色”或白色,它不是红色和白色,当我点击它时没有任何反应。这是我的代码:
public class Menu extends Activity implements OnClickListener, ConnectionCallbacks,
OnConnectionFailedListener{
private static final int REQUEST_CODE_RESOLVE_ERR = 9000;
private ProgressDialog mConnectionProgressDialog;
private PlusClient mPlusClient;
private ConnectionResult mConnectionResult;
private PlusOneButton mPlusOneButton;
ImageButton exit;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final PlusOneButton mPlusOneButton = new PlusOneButton(this);
mPlusClient = new PlusClient.Builder(this, this, this).clearScopes()
.build();
mPlusOneButton.initialize("https://market.android.com/details?id=" + getPackageName(),
new OnPlusOneClickListener() {
@Override
public void onPlusOneClick(Intent intent) {
mPlusOneButton.setVisibility(View.INVISIBLE);
startActivityForResult(intent, 0);
}
});
setContentView(R.layout.menu);
inicijalizujVars();
}
@Override
protected void onStart() {
super.onStart();
mPlusClient.connect();
}
@Override
protected void onStop() {
super.onStop();
mPlusClient.disconnect();
}
@Override
public void onConnectionFailed(ConnectionResult result) {
if (mConnectionProgressDialog.isShowing()) {
if (result.hasResolution()) {
try {
result.startResolutionForResult(this,
REQUEST_CODE_RESOLVE_ERR);
} catch (SendIntentException e) {
mPlusClient.connect();
}
}
}
mConnectionResult = result;
}
@Override
protected void onActivityResult(int requestCode, int responseCode,
Intent intent) {
if (requestCode == REQUEST_CODE_RESOLVE_ERR
&& responseCode == RESULT_OK) {
mConnectionResult = null;
mPlusClient.connect();
}
}
private void inicijalizujVars() {
exit = (ImageButton) findViewById(R.id.imageButtonExit);
exit.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
finish();
}
});
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
@Override
public void onResume(){
super.onResume();
}
@Override
public void onBackPressed()
{
super.onBackPressed();
}
@Override
public void onConnected(Bundle arg0) {
// TODO Auto-generated method stub
}
@Override
public void onDisconnected() {
// TODO Auto-generated method stub
}
}
我的布局xml中的按钮:
<com.google.android.gms.plus.PlusOneButton
xmlns:plus="http://schemas.android.com/apk/lib/com.google.android.gms.plus"
android:id="@+id/plus"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="30dp"
android:layout_marginTop="-30dp"
android:gravity="center"
plus:annotation="bubble"
plus:size="tall" />