Giphy / giphy-android-sdk

Home of the GIPHY SDK Android example app, along with Android SDK documentation, issue tracking, & release notes.
https://developers.giphy.com/
Mozilla Public License 2.0
94 stars 37 forks source link

Change Search Icon Color? #200

Closed muaviyaijaz123 closed 1 year ago

muaviyaijaz123 commented 1 year ago

Describe your question in detail.

I want to change search icon color to white used in the finding gif search view. How can i achieve that?

Currently using following version: implementation 'com.giphy.sdk:ui:2.3.4'

Additional contexts

Screenshot 2023-05-12 at 6 27 21 PM
ALexanderLonsky commented 1 year ago

Hey @muaviyaijaz123, Please refer to this comment.

In that version, you can achieve it by:

GPHCustomTheme.apply {
            val currentNightMode = this@DemoActivity?.let {
                this@DemoActivity.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK
            }
            val lightMode = (listOf(Configuration.UI_MODE_NIGHT_NO, Configuration.UI_MODE_NIGHT_UNDEFINED).contains(currentNightMode))
            defaultTextColor = Color.Black.hashCode()
            if (lightMode) {
                searchButtonIcon = ContextCompat.getDrawable(this@DemoActivity, com.giphy.sdk.ui.R.drawable.gph_ic_search_black)
            } else {
                searchButtonIcon = ContextCompat.getDrawable(this@DemoActivity, com.giphy.sdk.ui.R.drawable.gph_ic_search_white)
            }
        }
ALexanderLonsky commented 1 year ago

However, if you want to use the custom theme, you must redefine all colors for dark mode, as the default custom theme is a duplicate of the light one (unfortunately, there is currently no support for this scenario)

GPHCustomTheme.apply {
            val currentNightMode = this@DemoActivity?.let {
                this@DemoActivity.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK
            }
            val lightMode = (listOf(Configuration.UI_MODE_NIGHT_NO, Configuration.UI_MODE_NIGHT_UNDEFINED).contains(currentNightMode))
            if (lightMode) {
                searchButtonIcon = ContextCompat.getDrawable(this@DemoActivity, com.giphy.sdk.ui.R.drawable.gph_ic_search_black)
            } else {
                searchButtonIcon = ContextCompat.getDrawable(this@DemoActivity, com.giphy.sdk.ui.R.drawable.gph_ic_search_white)

                handleBarColor = 0xFF888888.toInt()

                emojiDrawerGradientTopColor = 0xFF212121.toInt()
                emojiDrawerGradientBottomColor = 0xFF1B1B1B.toInt()
                emojiDrawerSeparatorColor = 0xFF424242.toInt()

                searchBarBackgroundColor = 0xFF4E4E4E.toInt()
                searchTextColor = 0xFFFFFFFF.toInt()
                searchBackButtonColor = 0xFFFFFFFF.toInt()
                searchPlaceholderTextColor = ColorUtils.setAlphaComponent(searchTextColor, 0xCC)

                suggestionCellBackgroundColor = 0xFF212121.toInt()
                suggestionCellTextColor = 0xFFFFFFFF.toInt()

                tabBarSwitchDefaultColor = 0xC09A9A9A.toInt()
                tabBarSwitchSelectedColor = 0xFF00FF99.toInt()

                confirmationSelectButtonColor = 0xFF00FF99.toInt()
                confirmationSelectButtonTextColor = 0xFF121212.toInt()
                confirmationBackButtonColor = 0xFFD8D8D8.toInt()
                confirmationViewOnGiphyColor = 0xFFA6A6A6.toInt()

                backgroundColor = 0xFF121212.toInt()
                dialogOverlayBackgroundColor = 0x994E4E4E.toInt()
                defaultTextColor = 0xFFFFFFFF.toInt()
                usernameColor = 0xFFD8D8D8.toInt()
            }
        }
ALexanderLonsky commented 1 year ago

Update:

There is a new version available: implementation "com.giphy.sdk:ui:2.3.5-rc4"

Two new convenient functions are now available in the GPHCustomTheme.

applyLightThemeProps() / applyDarkThemeProps()

If you want to modify only certain color properties, you should use these functions:

GPHCustomTheme.apply {
            val currentNightMode = this@DemoActivity?.let {
                this@DemoActivity.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK
            }
            val lightMode = (listOf(Configuration.UI_MODE_NIGHT_NO, Configuration.UI_MODE_NIGHT_UNDEFINED).contains(currentNightMode))
            defaultTextColor = Color.Black.hashCode()
            if (lightMode) {
                applyLightThemeProps()
                searchButtonIcon = ContextCompat.getDrawable(this@DemoActivity, com.giphy.sdk.ui.R.drawable.gph_ic_search_black)
            } else {
                applyDarkThemeProps()
                searchButtonIcon = ContextCompat.getDrawable(this@DemoActivity, com.giphy.sdk.ui.R.drawable.gph_ic_search_white)
            }
        }
muaviyaijaz123 commented 1 year ago

Thanks for such detailed answer!

ALexanderLonsky commented 1 year ago

@muaviyaijaz123 Hey,

You can now switch to the official version.

muaviyaijaz123 commented 1 year ago

Sure, thanks for the update.