Added dark theme for Google sign-in button

This commit is contained in:
M66B 2022-07-17 09:14:34 +02:00
parent f22c89e67f
commit 9cb1dfe484
4 changed files with 48 additions and 4 deletions

View File

@ -192,25 +192,30 @@ public class FragmentOAuth extends FragmentBase {
});
if ("gmail".equals(id)) {
// https://developers.google.com/identity/branding-guidelines
final Context context = getContext();
final boolean dark = Helper.isDarkTheme(context);
int dp12 = Helper.dp2pixels(context, 12);
int dp24 = Helper.dp2pixels(context, 24);
Drawable g = context.getDrawable(R.drawable.google_logo);
g.setBounds(0, 0, g.getIntrinsicWidth(), g.getIntrinsicHeight());
btnOAuth.setCompoundDrawablesRelative(g, null, null, null);
btnOAuth.setCompoundDrawablePadding(dp24);
btnOAuth.setText(R.string.title_setup_google_sign_in);
btnOAuth.setCompoundDrawablePadding(dp12);
btnOAuth.setPaddingRelative(dp12, 0, dp12, 0);
btnOAuth.setTextColor(new ColorStateList(
new int[][]{
new int[]{android.R.attr.state_enabled},
new int[]{-android.R.attr.state_enabled},
},
new int[]{
Color.DKGRAY, // 0xff444444
dark ? Color.WHITE : Color.DKGRAY, // 0xff444444
Color.LTGRAY // 0xffcccccc
}
));
btnOAuth.setBackground(context.getDrawable(R.drawable.google_signin_background));
btnOAuth.setBackground(context.getDrawable(dark
? R.drawable.google_signin_background_dark
: R.drawable.google_signin_background_light));
btnOAuth.setPaddingRelative(dp12, 0, dp12, 0);
}
btnOAuth.setOnClickListener(new View.OnClickListener() {

View File

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="false">
<layer-list>
<item>
<shape>
<solid android:color="#FFFFFF" />
<stroke android:width="1dp" android:color="@color/google_blue" />
</shape>
</item>
<item>
<inset android:insetLeft="48dp" android:insetTop="1dp" android:insetRight="1dp" android:insetBottom="1dp">
<shape>
<solid android:color="@color/google_blue" />
</shape>
</inset>
</item>
</layer-list>
</item>
<item android:state_pressed="true">
<layer-list>
<item>
<shape>
<solid android:color="#FFFFFF" />
<stroke android:width="1dp" android:color="#FF0000" />
</shape>
</item>
<item>
<inset android:insetLeft="48dp" android:insetTop="1dp" android:insetRight="1dp" android:insetBottom="1dp">
<shape>
<solid android:color="@color/google_blue" />
</shape>
</inset>
</item>
</layer-list>
</item>
</selector>

View File

@ -163,4 +163,6 @@
<color name="solarizedBlue">#268bd2</color>
<color name="solarizedCyan">#2aa198</color>
<color name="solarizedGreen">#859900</color>
<color name="google_blue">#4285F4</color>
</resources>