Created
September 27, 2019 05:19
-
-
Save arthtilva/3680b21f8848da06b2994311163fc532 to your computer and use it in GitHub Desktop.
Manage Theme
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun setTheme(activity: Activity) { | |
StoreUserData(activity).setString( | |
Constants.DEVICE_ID, | |
Settings.Secure.getString(activity.contentResolver, Settings.Secure.ANDROID_ID) | |
) | |
if (StoreUserData(activity).getString(Constants.THEME_TYPE) == Constants.THEME_BLACK_WHITE) { | |
if (StoreUserData(activity).getString(Constants.FONT_SIZE) == Constants.FONT_LARGE) { | |
activity.setTheme(com.qirat.R.style.AppThemeBlackWhiteLarge) | |
} else { | |
activity.setTheme(com.qirat.R.style.AppThemeBlackWhiteSmall) | |
} | |
} else { | |
if (StoreUserData(activity).getString(Constants.FONT_SIZE) == Constants.FONT_LARGE) { | |
activity.setTheme(com.qirat.R.style.AppThemeLarge) | |
} else { | |
activity.setTheme(com.qirat.R.style.AppThemeSmall) | |
} | |
} | |
if (StoreUserData(activity).getString(Constants.USER_LANGUAGE_CODE).isEmpty()) { | |
StoreUserData(activity).setString(Constants.USER_LANGUAGE_CODE, "en") | |
} | |
val locale = Locale(StoreUserData(activity).getString(Constants.USER_LANGUAGE_CODE)) | |
Locale.setDefault(locale) | |
val config = Configuration() | |
config.setLocale(locale) | |
activity.baseContext.resources.updateConfiguration( | |
config, | |
activity.baseContext.resources.displayMetrics | |
) | |
} | |
SAMPLE - attrs | |
<attr name="cardViewBg" format="reference|color" /> | |
<attr name="toolbarTitleSize" format="dimension" /> | |
access | |
?attr/toolbarTitleSize |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment