Why isn’t there a getContentView() method for Activity?

I was able to get to the contents of an Activity with this call: ViewGroup view = (ViewGroup)getWindow().getDecorView(); You should probably check that getDecorView returns an instanceof ViewGroup for all cases, but with a LinearLayout in the Activity the code above runs fine. To get to the LinearLayout you could then just: LinearLayout content = … Read more

No resource identifier found for attribute ‘…’ in package ‘com.app….’

I just changed: xmlns:app=”http://schemas.android.com/apk/res-auto” to: xmlns:app=”http://schemas.android.com/apk/lib/com.app.chasebank” and it stopped generating the errors, com.app.chasebank is the name of the package. It should work according to this Stack Overflow : No resource identifier found for attribute ‘adSize’ in package ‘com.google.example’ main.xml

When it’s necessary to execute invalidate() on a View?

(Do consider accepting some answers) Generally, invalidate() means ‘redraw on screen’ and results to a call of the view’s onDraw() method. So if something changes and it needs to be reflected on screen, you need to call invalidate(). However, for built-in widgets you rarely, if ever, need to call it yourself. When you change the … Read more

Disable the touch events for all the views

Here is a function for disabling all child views of some view group: /** * Enables/Disables all child views in a view group. * * @param viewGroup the view group * @param enabled <code>true</code> to enable, <code>false</code> to disable * the views. */ public static void enableDisableViewGroup(ViewGroup viewGroup, boolean enabled) { int childCount = viewGroup.getChildCount(); … Read more

How can you tell if a View is visible on screen in Android?

This code works for me: public static boolean isVisible(final View view) { if (view == null) { return false; } if (!view.isShown()) { return false; } final Rect actualPosition = new Rect(); view.getGlobalVisibleRect(actualPosition); final Rect screen = new Rect(0, 0, getScreenWidth(), getScreenHeight()); return actualPosition.intersect(screen); }

Android – Attempt to invoke virtual method ‘void android.view.View.getBoundsOnScreen(android.graphics.Rect)’ on a null object reference

Problem is a known Android bug. From the Google issue tracker suggestions, setting the hint on the TextInputEditText seems to be causing the crash. Setting the hint only on the TextInputLayout fixes the crash. This issue only happens IF the hint is set on the nested EditText inside the TextInputLayout. I resolved it by setting … Read more