Search code examples
javaandroidtextviewjtextfield

Android: Why TextField is not showing?


    TextView t = new TextView(this);
    t.setX(0);
    t.setY(0);
    t.setText("Tap");
    t.setTextColor(Color.GREEN);
    t.setTextSize(25);
    t.setLayoutParams(new FrameLayout.LayoutParams(100, 100));
    setContentView(t);

I'am in ActionBarActivity, that why I'am using "this" as context, can't understand why the textField isn't showing, is here something wrong?


Solution

  • Try this one

        TextView t= new TextView(this);
        t.setX(0);
        t.setY(0);
        t.setText("Tap");
        t.setTextColor(Color.GREEN);
        t.setTextSize(25);
        addContentView(t, new FrameLayout.LayoutParams(100, 100));