android - 布局 Google 登录按钮 - Android

标签 android layout google-signin

我到处寻找,没有找到我想要的,我开始认为这是不可能的。

问题是:我有一个用于登录的 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/

相关文章:

jquery - 菜单锚定到最外层的 div

android - addOnLayoutChangeListener 与 addOnGlobalLayoutListener 与 post(Runnable r)

android - Flutter 谷歌登录为空

java - java中的撞球游戏——球碰撞算法

Android Google Maps V2 - OnInfoWindowClick on several markers

android - 使用 Android 版storm-gen 时如何访问底层 SQLite 数据库?

ios - 谷歌登录 404 错误与 swift

android:在没有 GET_ACCOUNTS 权限和 AccountPicker 的情况下获取设备上的谷歌帐户列表

HTML & CSS : Align text line to bottom center of div

Android Google 登录 : App Release Build Always Got "Error: 12500",,但调试版本未登录