我到处寻找,没有找到我想要的,我开始认为这是不可能的。
问题是:我有一个用于登录的 google 按钮,它是一个漂亮的按钮,但它不适合我的布局,我想使用我在 google 按钮中创建的图像,就像发生的情况一样在图像按钮中,这可能吗?如果是,我该怎么做?
谢谢
最佳答案
我有你的问题解决方案。我总是为 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()
返回之前添加此代码
ViewGroup.LayoutParams params = tv.getLayoutParams();
params.width = 100;
params.height = 70;
tv.setLayoutParams(params);
关于android - 布局 Google 登录按钮 - Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42059026/