I am having G+ signinbutton in my code and its working fine for login. I set it using below code in my xml
<com.google.android.gms.common.SignInButton
android:id="@+id/btn_sign_in"
android:layout_width="match_parent"
android:layout_height="50dp"
android:textSize="15dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp"
/>
What I have now is as below
Now I want to set TextView to center of button. but, SignInButton doesn't seem to have android:gravity
how can I set my TextView to center?
@Karan - use below code
, it's working for me.
SignInButton signInButton = ((SignInButton) findViewById(R.id.btn_sign_in));
for (int i = 0; i < signInButton.getChildCount(); i++) {
View v = signInButton.getChildAt(i);
if (v instanceof TextView) {
TextView tv = (TextView) v;
tv.setPadding(0, 0, 20, 0);
return;
}
}
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="@dimen/activity_horizontal_margin"
android:layout_marginLeft="@dimen/small_margin"
android:layout_marginRight="@dimen/small_margin"
android:layout_marginTop="@dimen/activity_horizontal_margin"
app:cardCornerRadius="@dimen/small_margin">
<RelativeLayout
android:id="@+id/sign_google"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:padding="@dimen/text_padding">
<ImageButton
android:id="@+id/img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/white"
android:src="@drawable/googleg_standard_color_18" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="@dimen/small_margin"
android:layout_toRightOf="@+id/img"
android:gravity="center"
android:text="@string/sign_in"
android:textColor="@color/black" />
</RelativeLayout>
</android.support.v7.widget.CardView>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.