Controlling view visibility from a resources

This is an old question that has already been accepted, but the following solution may help someone else: If you check res/values/attrs.xml in Android source code, you’ll see the definition of visibility property like this: <!– Controls the initial visibility of the view. –> <attr name=”visibility”> <!– Visible on screen; the default value. –> <enum … Read more

Android imageview change tint to simulate button click

happydude’s answer is the most elegant way to handle this but unfortunately (as pointed out in the comments) the source code for ImageView only accepts an integer (solid colour). Issue 18220 has been around for a couple years addressing this, I’ve posted a workaround there that I’ll summarize here: Extend ImageView and wrap drawableStateChanged() with … Read more

How to use selector to tint ImageView?

If you’re in API 21+ you can do this easily in XML with a selector and tint: <?xml version=”1.0″ encoding=”utf-8″?> <selector xmlns:android=”http://schemas.android.com/apk/res/android”> <item android:state_activated=”true”> <bitmap android:src=”https://stackoverflow.com/questions/19500039/@drawable/ic_settings_grey” android:tint=”@color/primary” /> </item> <item android:drawable=”https://stackoverflow.com/questions/19500039/@drawable/ic_settings_grey”/> </selector>

Applying ColorFilter to ImageView with ShapedDrawable

Alright, I had a quick play with this and noticed your issue of the circles disappearing. Without you describing what exactly you tried, I assume you haven’t tried setting the color filter to the Drawable itself yet? (as opposed to the ImageView, which only seems to work with BitmapDrawables). The following statements work perfectly fine … Read more

Byte array of image into imageview

This is how you can convert a Bitmap to a ByteArray and a ByteArray to a Bitmap: Convert Bitmap to ByteArray: Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher); ByteArrayOutputStream stream = new ByteArrayOutputStream(); bmp.compress(Bitmap.CompressFormat.PNG, 100, stream); byte[] byteArray = stream.toByteArray(); Convert ByteArray to Bitmap: Bitmap bmp = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length); ImageView image = (ImageView) findViewById(R.id.imageView1); image.setImageBitmap(Bitmap.createScaledBitmap(bmp, image.getWidth(), … Read more