public void init(final Context context, AttributeSet attrs, int defStyleAttr) { FrameLayout.LayoutParams params = new FrameLayout.LayoutParams( LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT); textInputLayout = new TextInputLayout(context); textInputLayout.setLayoutParams(params); String hint = attrs.getAttributeValue(ANDROID_NS, "hint"); if (hint != null) { textInputLayout.setHint(hint); } editText = new PermissionedEditText(context); editText.setSelectionListener(selectionListener); editText.setId(View.generateViewId()); editText.setLayoutParams(params); int inputType = attrs.getAttributeIntValue(ANDROID_NS, "inputType", EditorInfo.TYPE_NULL); if (inputType != EditorInfo.TYPE_NULL) { editText.setInputType(inputType); } textInputLayout.addView(editText, params); addView(textInputLayout); overlay = new FrameLayout(context); overlay.setLayoutParams( new FrameLayout.LayoutParams( LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT)); // overlay.setBackgroundColor(Color.BLACK); overlay.setBackgroundResource(R.drawable.permission_overlay_bg); overlay.setOnTouchListener( new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_UP) { Toast.makeText( getContext(), "This device does not have permission to view this field", 0) .show(); } return true; } }); overlay.setVisibility(GONE); TextView overlayLabel = new TextView(context); overlayLabel.setTextSize(24); overlayLabel.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL); overlayLabel.setText(hint + " Unavailable"); overlay.addView(overlayLabel); addView(overlay); actionButton = new ImageView(context); IconDrawable drawable = new IconDrawable(context, MaterialIcons.md_check); drawable.color(Color.GREEN); actionButton.setImageDrawable(drawable); actionButton.setLayoutParams(new FrameLayout.LayoutParams(100, 100, Gravity.RIGHT)); actionButton.setOnTouchListener( new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: { ImageView view = (ImageView) v; view.getDrawable().setColorFilter(0x77000000, PorterDuff.Mode.SRC_ATOP); view.invalidate(); break; } case MotionEvent.ACTION_UP: if (permissionedTextListener != null) { int aId = 0; if (mPrimaryAction != null) { aId = mPrimaryAction.id; } permissionedTextListener.onAction(aId, PermissionedTextLayout.this); } case MotionEvent.ACTION_CANCEL: { ImageView view = (ImageView) v; view.getDrawable().clearColorFilter(); view.invalidate(); break; } } return true; } }); actionButton.setVisibility(GONE); addView(actionButton); }