Android Button Drawable Tint

You can achieve coloring the drawableleft on a button with this method: Step 1: Create a drawable resource file with bitmap as parent element as shown below and name it as ic_action_landscape.xml under the drawable folder <?xml version=”1.0″ encoding=”utf-8″?> <bitmap xmlns:android=”http://schemas.android.com/apk/res/android” android:src=”https://stackoverflow.com/questions/30938620/@android:drawable/ic_btn_speak_now” android:tint=”@color/white” /> Step 2: Create your Button control in your layout as below … Read more

Android: How to check if a rectangle contains touched point?

Ok i solved my problem. I post the example code: Path p; Region r; @Override public void onDraw(Canvas canvas) { p = new Path(); p.moveTo(50, 50); p.lineTo(100, 50); p.lineTo(100, 100); p.lineTo(80, 100); p.close(); canvas.drawPath(p, paint); RectF rectF = new RectF(); p.computeBounds(rectF, true); r = new Region(); r.setPath(p, new Region((int) rectF.left, (int) rectF.top, (int) rectF.right, (int) … Read more

Get the displayed size of an image inside an ImageView

the following will work: ih=imageView.getMeasuredHeight();//height of imageView iw=imageView.getMeasuredWidth();//width of imageView iH=imageView.getDrawable().getIntrinsicHeight();//original height of underlying image iW=imageView.getDrawable().getIntrinsicWidth();//original width of underlying image if (ih/iH<=iw/iW) iw=iW*ih/iH;//rescaled width of image within ImageView else ih= iH*iw/iW;//rescaled height of image within ImageView (iw x ih) now represents the actual rescaled (width x height) for the image within the view (in other … Read more

Android Drawable: Specifying shape width in percent in the XML file?

You can’t specify a percentage. You need to specify a Dimension value to it. android:width is defined here: http://developer.android.com/reference/android/R.attr.html#width : (emphasis mine) Must be a dimension value, which is a floating point number appended with a unit such as “14.5sp”. Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font … Read more

Change background of EditText’s error message

I would suggest to use @Codeversed solution, but if it doesn’t fit for you for some reason you can use my custom EditText implementation. Usual EditText representation: EditText with error: In few words: I’ve created custom xml state for error display. See related code below: InputEditText.java: import android.annotation.TargetApi; import android.content.Context; import android.graphics.drawable.Drawable; import android.os.Build; import … Read more

How to create Drawable from resource

Your Activity should have the method getResources. Do: Drawable myIcon = getResources().getDrawable( R.drawable.icon ); As of API version 21 this method is deprecated and can be replaced with: Drawable myIcon = AppCompatResources.getDrawable(context, R.drawable.icon); If you need to specify a custom theme, the following will apply it, but only if API is version 21 or greater: … Read more