Android Set EditText Cursor Color

To set the EditText in Android you first need to set the textCursorDrawable to null. This is needed for Android 3.2 and up. android:textCursorDrawable=”@null” Setting this will result in the cursor color will be set to the textColor android:textColor  

Android Get Width And Height Of Image From Resource

In Android to get the width and height of an image from your res folder do the following: BitmapDrawable bd = (BitmapDrawable) this.getResources().getDrawable(R.drawable.icon); int height = bd.getBitmap().getHeight(); int width = bd.getBitmap().getWidth(); If you want the width and height depending the target density you can use the intrinsic values: BitmapDrawable bd = (BitmapDrawable) this.getResources().getDrawable(R.drawable.icon); int imageHeight =

Read More

Android Follow Test Method Naming Conventions

When naming test methods, you can use an underscore to separate what is being tested from the specific case being tested. This style makes it easier to see exactly what cases are being tested. For example: testMethod_specificCase1 testMethod_specificCase2 void testIsDistinguishable_protanopia() { ColorMatcher colorMatcher = new ColorMatcher(PROTANOPIA) assertFalse(colorMatcher.isDistinguishable(Color.RED, Color.BLACK)) assertTrue(colorMatcher.isDistinguishable(Color.X, Color.Y)) } Source: http://source.android.com/source/code-style.html

Android Be Consistent

Our parting thought: BE CONSISTENT. If you’re editing code, take a few minutes to look at the code around you and determine its style. If they use spaces around their if clauses, you should too. If their comments have little boxes of stars around them, make your comments have little boxes of stars around them

Read More

Android Log Sparingly

While logging is necessary it has a significantly negative impact on performance and quickly loses its usefulness if it’s not kept reasonably terse. The logging facilities provides five different levels of logging. Below are the different levels and when and how they should be used. ERROR: This level of logging should be used when something

Read More

Eclipse Java TODO Comments

Use TODO comments for code that is temporary, a short-term solution, or good-enough but not perfect. TODOs should include the string TODO in all caps, followed by a colon: // TODO: Remove this code after the UrlTable2 has been checked in. and // TODO: Change this to use a flag instead of a constant. If

Read More