我到处寻找,但没有找到我想要的,我开始认为这是不可能的。
这里有一个问题:我有一个用于登录的google按钮,它是一个漂亮的按钮,但它不适合我的布局,我想使用一个由我在google按钮中创建的图像,就像在图像按钮中发生的那样,这可能吗?如果是,我该怎么做?
谢谢
发布于 2017-02-06 14:50:34
我有你的问题的答案。我总是试着为谷歌plus定制SignIn按钮。
试试这个,这是我测试过的。
这是代码。
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()中返回之前添加此代码
ViewGroup.LayoutParams params = tv.getLayoutParams();
params.width = 100;
params.height = 70;
tv.setLayoutParams(params);发布于 2018-11-21 17:46:34
没有必要使用谷歌登录按钮,如果它不适合你的布局。您可以简单地创建自己的按钮与自己的设计和在OnClick方法只创建谷歌登录意图。
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);
}
});发布于 2017-02-06 14:39:30
您可以创建自己的按钮,并使用XML tag android:drawableLeft="@drawable\file"在按钮上显示任何图像。
https://stackoverflow.com/questions/42059026
复制相似问题