Difference between app:srcCompat and android:src in Android’s layout XML

app:srcCompat is the most foolproof method of integrating vector drawables into your app.Vector drawables allow you to replace multiple png assets with a single vector graphic, defined in XML. While previously limited to Lollipop and higher devices Note As of Android Support Library 23.3.0, support vector drawables can only be loaded via app:srcCompat . you … Read more

‘Missing contentDescription attribute on image’ in XML

Follow this link for solution: Android Lint contentDescription warning Resolved this warning by setting attribute android:contentDescription for my ImageView android:contentDescription=”@string/desc” Android Lint support in ADT 16 throws this warning to ensure that image widgets provide a contentDescription This defines text that briefly describes the content of the view. This property is used primarily for accessibility. … Read more

How to create a circular ImageView in Android? [duplicate]

I too needed a rounded ImageView, I used the below code, you can modify it accordingly: import android.content.Context; import android.graphics.Bitmap; import android.graphics.Bitmap.Config; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.PorterDuff.Mode; import android.graphics.PorterDuffXfermode; import android.graphics.Rect; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.util.AttributeSet; import android.widget.ImageView; public class RoundedImageView extends ImageView { public RoundedImageView(Context context) { super(context); } public … Read more

How to clear an ImageView in Android?

I used to do it with the dennis.sheppard solution: viewToUse.setImageResource(0); it works but it is not documented so it isn’t really clear if it effects something else in the view (you can check the ImageView code if you like, i didn’t). I think the best solution is: viewToUse.setImageResource(android.R.color.transparent); I like this solution the most cause … Read more

Changing ImageView source

Changing ImageView source: Using setBackgroundResource() method: myImgView.setBackgroundResource(R.drawable.monkey); you are putting that monkey in the background. I suggest the use of setImageResource() method: myImgView.setImageResource(R.drawable.monkey); or with setImageDrawable() method: myImgView.setImageDrawable(getResources().getDrawable(R.drawable.monkey)); *** With new android API 22 getResources().getDrawable() is now deprecated. This is an example how to use now: myImgView.setImageDrawable(getResources().getDrawable(R.drawable.monkey, getApplicationContext().getTheme())); and how to validate for old API … Read more

How to scale an Image in ImageView to keep the aspect ratio

Yes, by default Android will scale your image down to fit the ImageView, maintaining the aspect ratio. However, make sure you’re setting the image to the ImageView using android:src=”…” rather than android:background=”…”. src= makes it scale the image maintaining aspect ratio, but background= makes it scale and distort the image to make it fit exactly … Read more

How to make an ImageView with rounded corners?

This is pretty late in response, but for anyone else that is looking for this, you can do the following code to manually round the corners of your images. http://www.ruibm.com/?p=184 This isn’t my code, but I’ve used it and it’s works wonderfully. I used it as a helper within an ImageHelper class and extended it … Read more

findViewById in Fragment

Use getView() or the View parameter from implementing the onViewCreated method. It returns the root view for the fragment (the one returned by onCreateView() method). With this you can call findViewById(). @Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { ImageView imageView = (ImageView) getView().findViewById(R.id.foo); // or (ImageView) view.findViewById(R.id.foo); As getView() works only after onCreateView(), … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)