tags:

views:

47

answers:

2

I am trying to create a "hidden edit view" which will give me the functionality of text editing within a 3rd party GUI on Android. I figured that the easiest way to make it not draw would be to just override onDraw() with a no-op; however it's having no effect. I've added a log statement to check that it is being called. Does anyone have an idea why it's still being drawn?

    private class HiddenEditText extends EditText
{
    public HiddenEditText(Context context)
    {
        super(context);
    }

    @Override
    protected void onDraw(Canvas canvas)
    {
        Log.e("DBG", "onDraw()");
    }
}

    // ...    

EditText EditTextGreen = new HiddenEditText(this);
    EditTextGreen.setFocusable(true);
    EditTextGreen.setLayoutParams(new TableLayout.LayoutParams(TableLayout.LayoutParams.FILL_PARENT, TableLayout.LayoutParams.WRAP_CONTENT));

    layout.addView(EditTextGreen, 0);
+1  A: 

Another way of achieving this result, is to specify the background of the EditText as transparent:

<EditText android:background="@android:color/transparent" ...
Mannaz
Can that be done programmatically?
spurserh
((EditText) findViewById(R.id.MyEditTextId)).setBackgroundDrawable(android.R.color.transparent);
Mannaz
+1  A: 

The background is drawn by View.draw(). onDraw() is invoked by View.draw(), so you need to follow Mannaz' advice and set the background to a transparent color or just set it to null.

Romain Guy