Issue
I have Button where I want to set DrawableLeft. This code down below is working as intended for most of Android devices but for Huawei and Samsung it is not working and drawable has default color on screen.
That means icon.setTint(ContextCompat.getColor(app, R.color.colorTextDarkGrey))
is not working for some reason.
This app was tested on devices with API level 23 or higher. (Older versions are not supported). It was also tested on Android 6.0 and Android 7.1 and it worked.
Huawei phone is Android 8.0 and Samsung phone is Android 9.0
private fun setPrevButton(){
App.log("ButtonSetters: setPrevButtonVariant()")
val icon = app.resources.getDrawable(R.drawable.arrow_black_short_left, null)
icon.setTint(ContextCompat.getColor(app, R.color.colorTextDarkGrey))
backBtn.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null)
}
Solution
Please follow below code to solved this issue.
val unwrappedDrawable = AppCompatResources.getDrawable(context, R.drawable.my_drawable)
val wrappedDrawable = DrawableCompat.wrap(unwrappedDrawable!!)
DrawableCompat.setTint(wrappedDrawable, Color.RED)
Answered By - Jyubin Patel
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.