我无论到哪里都没有找到我想要的东西,我开始觉得这是不可能的。
问题在这里:我有一个用于登录的谷歌按钮,它很漂亮,但它不适合我的布局,我想使用我自己创建的谷歌按钮图片,就像图像按钮中发生的那样,这可能吗?如果可以,我该怎么做?
谢谢
问题在这里:我有一个用于登录的谷歌按钮,它很漂亮,但它不适合我的布局,我想使用我自己创建的谷歌按钮图片,就像图像按钮中发生的那样,这可能吗?如果可以,我该怎么做?
谢谢
我有你的问题解决方案。我一直尝试为Google Plus创建自定义登录按钮。
请尝试此方法,它已由我测试过。
以下是代码。
XML布局
<com.google.android.gms.common.SignInButton
android:id="@+id/google_button"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:text="Text"
android:layout_alignParentTop="true"
android:layout_margin="10dp"
android:textSize="18sp" />
个性化定制方法
private void googleBtnUi() {
// TODO Auto-generated method stub
SignInButton googleButton = (SignInButton) findViewById(R.id.google_button);
googleButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
for (int i = 0; i < googleButton.getChildCount(); i++) {
View v = googleButton.getChildAt(i);
if (v instanceof TextView)
{
TextView tv = (TextView) v;
tv.setTextSize(14);
tv.setTypeface(null, Typeface.NORMAL);
tv.setText("My Text");
tv.setTextColor(Color.parseColor("#FFFFFF"));
tv.setBackgroundDrawable(getResources().getDrawable(
R.drawable.ic_launcher));
tv.setSingleLine(true);
tv.setPadding(15, 15, 15, 15);
return;
}
}
}
在googleBtnUi()
方法中的return语句之前添加此代码
ViewGroup.LayoutParams params = tv.getLayoutParams();
params.width = 100;
params.height = 70;
tv.setLayoutParams(params);
Button myGoogleBtn = (Button) findViewById(R.id.loginGoogle);
myGoogleBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent signInIntent = mGoogleSignInClient.getSignInIntent();
startActivityForResult(signInIntent, RC_SIGN_IN);
}
});
android:drawableLeft="@drawable\file"
在按钮上显示任何图像。