Question

There is difference between text edit added in activity_main.xml and one added from code.

That is how they look.

text fields

Code of EditText added from xml.

xml code

And code of EditText added programmatically.

code

Function getDisplayInfo just get width and height of the screen. It does nothing connected with ui.

Was it helpful?

Solution

It looks like it's because the background color isn't set on the new EditText since the background color is set in xml then you add a View to it. You need to then set the background color to your newly added EditText.

I believe something like

editT.setBackgroundColor(Color.parseColor("#0F0"));

should work.

OTHER TIPS

EditText added from xml has preformed look and feel but if we are adding it from java code it may require to set additional attributes to set look and feel

EditText etName = new EditText(getApplicationContext());
etName.setBackgroundResource(R.drawable.BlueBackground);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top