Android Google 登录按钮和 Facebook sdk 4+ 按钮布局
Android Google Login Button and Facebook sdk 4+ Button Layout
我正在开发一个使用 google and facebook 集成的应用程序...我想修复那些按钮的高度和宽度...我想手动设置按钮文本...
到目前为止我已经试过了
<com.facebook.login.widget.LoginButton
xmlns:fb="http://schemas.android.com/apk/res-auto"
android:id="@+id/connectWithFbButton"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:text="@string/fbloginText"
android:layout_marginTop="30dp"
/>
<com.google.android.gms.common.SignInButton
android:id="@+id/signin"
android:layout_width="match_parent"
android:layout_height="50dp"
android:text="@string/googleloginText"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="20dp"/>
虽然我曾尝试过这样的事情
fb:login_text="Login"
fb:logout_text="Logout"
or
facebook:login_text="Login"
但我遇到错误::=>在包 'com.test.b2c'
中找不到属性 'login_text' 的资源标识符
或通过编码
loginButton = (LoginButton) findViewById(R.id.connectWithFbButton);
loginButton.setText("Login");
现在我的布局看起来像这样
我也想设置这个按钮的高度和宽度.. ...
帮助我的朋友.....提前谢谢
更新
我在设置宽度方面没有直接问题,我真正担心的是图片中显示的高度不一致。我需要找到更好的方法来使这些按钮的高度相等,然后将文本设置为这些按钮。
您只需更改
android:layout_width="any size in dps"
android:layout_height="any size in dps"
您必须将 android:layout_width
更改为 wrap_content
或特定大小,最好以 dp 为单位(例如 20dp
、30dp
、40dp
) .
至于错误,可能是因为您没有编辑 strings.xml,请尝试使用 Android Studio,它会自动为您创建这些值,并且还会显示给您您的应用程序预览。
添加线性布局并在其中添加这两个按钮:
<LinearLayout
android:id="@+id/parentLinear"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<com.facebook.login.widget.LoginButton
xmlns:fb="http://schemas.android.com/apk/res-auto"
android:id="@+id/connectWithFbButton"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:text="@string/fbloginText"
android:layout_marginTop="30dp" />
<com.google.android.gms.common.SignInButton
android:id="@+id/signin"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:text="@string/googleloginText"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="30dp" />
</LinearLayout>
这将为两个按钮[=11]提供正确的高度、宽度和边距 =]
在您的 Facebook 小部件中添加以下内容:
android:paddingTop="20dp"
android:paddingBottom="20dp"
loginView:login_text="your custom text here"
更新
您还需要包括:
xmlns:loginView="http://schemas.android.com/apk/res-auto"
如果我们想更改 Facebook 登录的自定义文本..
转到那个 Facebook 图书馆项目然后转到 string.xml
你会发现这样的东西
<string name="com_facebook_loginview_log_in_button_long">Log in with facebook </string>
将其替换为您的自定义文本
尽管如果您想更改 Google 的自定义文本,您可以
从 OnCreate 调用这个
setGooglePlusButtonText(signinButton,"your custom text");
//Google加
的文本变化方法
protected void setGooglePlusButtonText(SignInButton signInButton,
String buttonText) {
for (int i = 0; i < signInButton.getChildCount(); i++) {
View v = signInButton.getChildAt(i);
if (v instanceof TextView) {
TextView tv = (TextView) v;
tv.setTextSize(15);
tv.setTypeface(null, Typeface.NORMAL);
tv.setText(buttonText);
return;
}
}
}
为了 facebook 的高度不一致,我在 Facebook 按钮上添加了填充 XML
android:paddingTop="20dp"
android:paddingBottom="20dp"
<com.facebook.login.widget.LoginButton
xmlns:fb="http://schemas.android.com/apk/res-auto"
fb:com_facebook_login_text="Your Text"
此 xml 样式代码自定义我的应用程序的 facebook 登录按钮,如图中所示(文本和按钮大小)。
<com.facebook.login.widget.LoginButton
android:id="@+id/login_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="40dip"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:textSize="20sp"
facebook:com_facebook_login_text="Facebook"
facebook:com_facebook_logout_text="Facebook" />
结果:
我正在开发一个使用 google and facebook 集成的应用程序...我想修复那些按钮的高度和宽度...我想手动设置按钮文本...
到目前为止我已经试过了
<com.facebook.login.widget.LoginButton
xmlns:fb="http://schemas.android.com/apk/res-auto"
android:id="@+id/connectWithFbButton"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:text="@string/fbloginText"
android:layout_marginTop="30dp"
/>
<com.google.android.gms.common.SignInButton
android:id="@+id/signin"
android:layout_width="match_parent"
android:layout_height="50dp"
android:text="@string/googleloginText"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="20dp"/>
虽然我曾尝试过这样的事情
fb:login_text="Login"
fb:logout_text="Logout"
or
facebook:login_text="Login"
但我遇到错误::=>在包 'com.test.b2c'
中找不到属性 'login_text' 的资源标识符或通过编码
loginButton = (LoginButton) findViewById(R.id.connectWithFbButton);
loginButton.setText("Login");
现在我的布局看起来像这样
我也想设置这个按钮的高度和宽度.. ... 帮助我的朋友.....提前谢谢
更新
我在设置宽度方面没有直接问题,我真正担心的是图片中显示的高度不一致。我需要找到更好的方法来使这些按钮的高度相等,然后将文本设置为这些按钮。
您只需更改
android:layout_width="any size in dps"
android:layout_height="any size in dps"
您必须将 android:layout_width
更改为 wrap_content
或特定大小,最好以 dp 为单位(例如 20dp
、30dp
、40dp
) .
至于错误,可能是因为您没有编辑 strings.xml,请尝试使用 Android Studio,它会自动为您创建这些值,并且还会显示给您您的应用程序预览。
添加线性布局并在其中添加这两个按钮:
<LinearLayout
android:id="@+id/parentLinear"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<com.facebook.login.widget.LoginButton
xmlns:fb="http://schemas.android.com/apk/res-auto"
android:id="@+id/connectWithFbButton"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:text="@string/fbloginText"
android:layout_marginTop="30dp" />
<com.google.android.gms.common.SignInButton
android:id="@+id/signin"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:text="@string/googleloginText"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="30dp" />
</LinearLayout>
这将为两个按钮[=11]提供正确的高度、宽度和边距 =]
在您的 Facebook 小部件中添加以下内容:
android:paddingTop="20dp"
android:paddingBottom="20dp"
loginView:login_text="your custom text here"
更新
您还需要包括:
xmlns:loginView="http://schemas.android.com/apk/res-auto"
如果我们想更改 Facebook 登录的自定义文本..
转到那个 Facebook 图书馆项目然后转到 string.xml
你会发现这样的东西
<string name="com_facebook_loginview_log_in_button_long">Log in with facebook </string>
将其替换为您的自定义文本
尽管如果您想更改 Google 的自定义文本,您可以
从 OnCreate 调用这个
setGooglePlusButtonText(signinButton,"your custom text");
//Google加
的文本变化方法protected void setGooglePlusButtonText(SignInButton signInButton,
String buttonText) {
for (int i = 0; i < signInButton.getChildCount(); i++) {
View v = signInButton.getChildAt(i);
if (v instanceof TextView) {
TextView tv = (TextView) v;
tv.setTextSize(15);
tv.setTypeface(null, Typeface.NORMAL);
tv.setText(buttonText);
return;
}
}
}
为了 facebook 的高度不一致,我在 Facebook 按钮上添加了填充 XML
android:paddingTop="20dp"
android:paddingBottom="20dp"
<com.facebook.login.widget.LoginButton
xmlns:fb="http://schemas.android.com/apk/res-auto"
fb:com_facebook_login_text="Your Text"
此 xml 样式代码自定义我的应用程序的 facebook 登录按钮,如图中所示(文本和按钮大小)。
<com.facebook.login.widget.LoginButton
android:id="@+id/login_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="40dip"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:textSize="20sp"
facebook:com_facebook_login_text="Facebook"
facebook:com_facebook_logout_text="Facebook" />
结果: