我可以编辑Google上的登录按钮文字吗?

时间:2013-08-04 07:38:43

标签: android google-play-services google-plus google-signin

我正在将我的应用程序与google plus集成。我已经安装了Google Play服务并登录了我的帐户。我也可以发布并加一个我想要的东西。

我的问题

我无法更改登录按钮的文字。

我的代码

<com.google.android.gms.common.SignInButton
        android:id="@+id/share_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:text="Share on Google+" />

我试过了什么?

  • 首先,我尝试将此行添加到xml

    android:text="Share on Google+"
    
  • 其次,我尝试以编程方式设置文本,但它不起作用。

任何帮助都将不胜感激。

修改

如果不可能,有什么办法让我可以在另一个按钮上使用相同的谷歌登录按钮吗?

8 个答案:

答案 0 :(得分:93)

这是我使用的技术:

protected void setGooglePlusButtonText(SignInButton signInButton, String buttonText) {
    // Find the TextView that is inside of the SignInButton and set its text
    for (int i = 0; i < signInButton.getChildCount(); i++) {
        View v = signInButton.getChildAt(i);

        if (v instanceof TextView) {
            TextView tv = (TextView) v;
            tv.setText(buttonText);
            return;
        }
    }
}

答案 1 :(得分:24)

这是我使用的最简单方法:

[PHP]
engine = On
cgi.check_shebang_line = 1
cgi.fix_pathinfo=1
cgi.discard_path=1
cgi.force_redirect=0
date.timezone=UTC
;cgi.redirect_status_env = REMOTE_ADDR

short_open_tag = On
asp_tags = Off
precision    =  12
y2k_compliance = On
output_buffering = Off
zlib.output_compression = Off
implicit_flush = Off
unserialize_callback_func=
serialize_precision = 100

safe_mode = Off
safe_mode_gid = Off
safe_mode_include_dir =        
safe_mode_exec_dir =
safe_mode_allowed_env_vars = PHP_
safe_mode_protected_env_vars = LD_LIBRARY_PATH

;disable_functions = highlight_file, diskfreespace, exec, passthru, system, popen, fsockopen, pfsockpen, show_source, php_uname, ini_alter, ini_restore, getrusage, get_current_user, set_time_limit, getmyuid, getmypid, dl, leak, listen, chown, chmod, chgrp, realpath, tmpfile, link 
disable_functions = 

disable_classes =
expose_php = Off

error_reporting = E_ALL & ~E_NOTICE
display_errors = On
display_startup_errors = On
log_errors = Off

log_errors_max_len = 1024
ignore_repeated_errors = Off
ignore_repeated_source = Off

report_memleaks = On
track_errors = Off

;error_prepend_string = ""

variables_order = "EGPCS"
;register_globals = On
register_argc_argv = On

post_max_size = 20M
memory_limit = 64M
gpc_order = "GPC"


magic_quotes_runtime = Off    
magic_quotes_sybase = Off
;auto_prepend_file = /var/www/index.php

;auto_append_file =

default_mimetype = "text/html"

doc_root = 
user_dir = 
enable_dl = On

file_uploads = On
upload_tmp_dir = /tmp
upload_max_filesize = 15M
allow_url_fopen = On
default_socket_timeout = 60

[Syslog]
define_syslog_variables  = Off

[mail function]
sendmail_path = /usr/local/bin/sendmail -oi -t

[Java]

[SQL]
sql.safe_mode = Off

[ODBC]
;odbc.allow_persistent = On
;odbc.check_persistent = On
;odbc.max_persistent = -1
;odbc.max_links = -1  
;odbc.defaultlrl = 4096  
;odbc.defaultbinmode = 1  

[MySQL]
mysql.allow_persistent = Off
mysql.max_persistent = -1
mysql.max_links = -1
mysql.default_port = 3306
mysql.default_socket =
mysql.default_host =
mysql.default_user =
mysql.default_password =
mysql.connect_timeout = 10
mysql.trace_mode = Off

[MySQLi]
mysqli.max_persistent = -1
;mysqli.allow_local_infile = On
mysqli.allow_persistent = On
mysqli.max_links = -1
mysqli.cache_size = 2000
mysqli.default_port = 3306
mysqli.default_socket =
mysqli.default_host =
mysqli.default_user =
mysqli.default_pw =
mysqli.reconnect = On

[mSQL]
;msql.allow_persistent = On
;msql.max_persistent = -1
;msql.max_links = -1

[PostgresSQL]
;pgsql.allow_persistent = On
;pgsql.auto_reset_persistent = Off 
;pgsql.max_persistent = -1
;pgsql.max_links = -1
;pgsql.ignore_notice = 0
;pgsql.log_notice = 0

[Sybase]
;sybase.allow_persistent = On
;sybase.max_persistent = -1
;sybase.max_links = -1
;sybase.min_error_severity = 10
;sybase.min_message_severity = 10
;sybase.compatability_mode = Off

[Sybase-CT]
;sybct.allow_persistent = On
;sybct.max_persistent = -1
;sybct.max_links = -1
;sybct.min_server_severity = 10
;sybct.min_client_severity = 10

[dbx]
;dbx.colnames_case = "unchanged"

[bcmath]
bcmath.scale = 0

[browscap]

[Informix]
;ifx.default_host =
;ifx.default_user =
;ifx.default_password =
;ifx.allow_persistent = On
;ifx.max_persistent = -1
;ifx.max_links = -1
;ifx.textasvarchar = 0
;ifx.byteasvarchar = 0
;ifx.charasvarchar = 0
;ifx.blobinfile = 0
;ifx.nullformat = 0

[Session]
session.save_handler = files
;session.save_handler=mm
session.use_cookies = 1
session.name = PHPSESSID
session.auto_start = 0
session.cookie_lifetime = 0
session.cookie_path = /
session.cookie_domain =
session.serialize_handler = php
session.gc_divisor     = 100
session.gc_maxlifetime = 1440

session.bug_compat_42 = 1
session.bug_compat_warn = 1

session.referer_check =
session.entropy_length = 0
session.entropy_file =

session.cache_limiter = nocache
session.cache_expire = 180
session.use_trans_sid = 0
session.save_path = /tmp

url_rewriter.tags = "a=href,area=href,frame=src,input=src,form=,fieldset="

[MSSQL]
;mssql.allow_persistent = On
;mssql.max_persistent = -1
;mssql.max_links = -1
;mssql.min_error_severity = 10
;mssql.min_message_severity = 10
;mssql.compatability_mode = Off
;mssql.secure_connection = Off

[Assertion]

[Ingres II]
;ingres.allow_persistent = On
;ingres.max_persistent = -1
;ingres.max_links = -1
;ingres.default_database =
;ingres.default_user =
;ingres.default_password =

[Verisign Payflow Pro]
pfpro.defaulthost = "test-payflow.verisign.com"
pfpro.defaultport = 443
pfpro.defaulttimeout = 30

[com]

[Printer]

[mbstring]

[FrontBase]

[Crack]

[exif]

[Pdo]
extension=pdo_mysql.so
extension=pdo_pgsql.so

[extensions]

;extension=apc.so
;apc.optimization = 3
;apc.slam_defense = 75
;  extension=apc.so
;  apc.enabled=1
;  apc.shm_segments=1
;  apc.optimization=0
;  apc.shm_size=16
;  apc.ttl=7200
;  apc.user_ttl=7200
;  apc.num_files_hint=1024
;  apc.mmap_file_mask=/tmp/apc.XXXXXX
;  apc.enable_cli=1

extension=curl.so
;extension=ftp.so
;extension=id3.so
;extension=imagick.so
;extension=imap.so
;extension=openssl.so
;extension=intl.so
extension=pgsql.so
;extension=soap.so
;extension=xsl.so
;extension=yaml.so
;extension=memcached.so
;extension=memcache.so
;extension=gmp.so
;extension=mongo.so
;extension=mongodb.so

; Uncomment the line below to enable Ioncube Loader:
;zend_extension = /usr/local/ioncube/ioncube_loader_lin_7.1.so
; Uncomment the line below to enable ZendGuardLoader:
;zend_extension=/usr/local/ZendGuardLoader-php-5.3-linux-glibc23-i386/php-5.3.x/ZendGuardLoader.so
;zend_loader.disable_licensing=0

答案 2 :(得分:11)

<强>问题:

其他答案提到了一种解决方法。按钮的底层实现可能会随时更改,从而导致代码中断。尝试使用黑客行为让我觉得不舒服。对于一个干净的解决方案,您会认为在布局文件中android:text上设置com.google.android.gms.common.SignInButton可以解决问题。但事实证明,该属性不适用于SignInButton

<强>目标

Google指南

从文档中,Google建议创建Customizing the Sign-In Button中提到的自定义按钮。然后它建议使用Sign-In Branding Guidelines中提到的品牌指南。这包括在按钮中使用给定的自定义图标和图像,设置特定的文本大小,填充以及其他标识和标记。

清洁解决方案

根据Google的建议,我们需要做一些自定义工作。我愿意这样做但是想创造一些可重复使用的东西,以便其他人不必再次经历这一点。这就是我写一个快速小(4KB)库的原因。如果您发现问题,请随时为每个人做出贡献。

  • 第1步:将以下内容添加到app模块级build.gradle文件中:

    dependencies {
        compile 'com.shobhitpuri.custombuttons:google-signin:1.0.0'
    }
    
  • 第2步:在XML布局中,请执行以下操作:

    <RelativeLayout
        ...
        xmlns:app="http://schemas.android.com/apk/res-auto">
    
        <com.shobhitpuri.custombuttons.GoogleSignInButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:text="@string/google_sign_up"
            app:isDarkTheme="true" />
    </RelativeLayout>
    

<强>用法

  • android:text="{string}" :像往常一样设置按钮上的文字。

  • app:isDarkTheme="{Boolean}" :在按钮的蓝色主题和白色主题之间切换。该库处理文本颜色和背景颜色的更改。它还可以处理按钮按下或按钮点击时的颜色变化。

<强>来源:

希望它有所帮助。

答案 3 :(得分:1)

android:text无效,因为Google的登录按钮为FrameLayout,但不是Button

由于text属性仅适用于表示文本格式但不适用于ViewGroups的视图,因此您的解决方案无效。

您可以实现的唯一方法是按照 w.donahue 的说明,在TextView内定义FrameLayout

答案 4 :(得分:1)

初学者

避免碰撞。

try {
            ((TextView) mGoogleSignOutBtn.getChildAt(0)).setText(R.string.sign_out);
} catch (ClassCastException | NullPointerException e) {
            e.printStackTrace();
}

答案 5 :(得分:1)

这对我有用:

XML 文件

<com.google.android.gms.common.SignInButton
         android:id="@+id/google_login_button"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:visibility="gone"
                    />
                <Button
                    android:id="@+id/new_googlebtn"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:backgroundTint="@color/white"
                    android:text="@string/google_login"
                    android:textColor="@color/black"
                    app:icon="@drawable/googleg_standard_color_18"
                    app:iconGravity="textStart"
                    app:iconPadding="10dp"
                    app:iconTint="#00100D0D"
                    app:iconTintMode="src_atop" />

未修改的主要活动文件

google_signInButton=findViewById(R.id.google_login_button);
        google_signInButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                    Intent intent = Auth.GoogleSignInApi.getSignInIntent(googleApiClient);
                    startActivityForResult(intent, SIGN_IN);

            }
        });

更新的主要活动文件

google_signInButton=findViewById(R.id.google_login_button);
        new_googlebtn=findViewById(R.id.new_googlebtn);
        new_googlebtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if (v== new_googlebtn) {
                    google_signInButton.performClick();
                }
                    Intent intent = Auth.GoogleSignInApi.getSignInIntent(googleApiClient);
                    startActivityForResult(intent, SIGN_IN);

            }
        });

答案 6 :(得分:0)

我鼓励不要使用那些@ w.donahue aproach,因为暴力的几个原则是开/闭原则。最好的apraoch它可以让你自己唱歌按钮。如果您在google plus按钮中看到有关Sing的文档,则只是带有textview的frameLayout。在此链接https://developers.google.com/+/branding-guidelines#sign-in-button,您有材料来设计按钮。

public class GplusButton extends FrameLayout {

private final String logIn="log in with google +";

private final String logOut="log out";

TextView labelTV;

public GplusButton(Context context) {
    super(context, null);
}

public GplusButton(Context context, AttributeSet attrs) {
    super(context, attrs);
    setBackgroundResource(R.drawable.btn_g_plus_signin_normal);
    addTextLabel();
}

public void addTextLabel() {
    labelTV = new TextView(getContext());
    setTextLogIn();
    labelTV.setTextColor(Color.WHITE);
    FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(
            LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    params.gravity = Gravity.CENTER;
    addView(labelTV, params);
}

public void setTextLogIn(){
    labelTV.setText(logIn);
}

public void setTextLogOut(){
    labelTV.setText(logOut);

}

唯一令人讨厌的事情是,即使谷歌+标记9补丁扩展他们不是,所以你必须编辑

答案 7 :(得分:0)

您可以使用我根据您在此页面中找到的.reverse_order(:field)答案撰写的这个课程:

w.donahue