[Html] [html] package com. mrzhu. edittest; import android. app. activity; import android. OS. bundle; import android. view. viewGroup; import android. widget. relativeLayout; public class EditTestActivity extends Activity {/** Called when the activity is first created. * // @ Override public void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); // custom EditText component EditTextTest ed = New EditTextTest (this); // set to input text ed from 140px on the left. setPadding (140, 0, 0, 0); // load a layout file and dynamically add an EditText RelativeLayout relativeLayout = (RelativeLayout) getLayoutInflater () to the layout (). inflate (R. layout. main, null); // create a LayoutParams object RelativeLayout. layoutParams layoutParams = new RelativeLayout. layoutParams (ViewGroup. layoutParams. FILL_PARENT, ViewGroup. layoutParams. WRAP_CONTENT); // set the android: layout_below Value of layoutParams. addRule (RelativeLayout. BELOW, R. id. button2); // dynamically add EditText relativeLayout. addView (ed, layoutParams); // setContentView (relativeLayout);} custom EditText control: [html] www.2cto. compackage com. mrzhu. edittest; import android. content. context; import android. graphics. canvas; import android. graphics. color; import android. graphics. paint; import android. util. attributeSet; import android. w Idget. editText; public class EditTextTest extends EditText {public EditTextTest (Context context) {super (context);} public EditTextTest (Context context, AttributeSet attrs, int defStyle) {super (context, attrs, defStyle);} public EditTextTest (Context context, AttributeSet attrs) {super (context, attrs) ;}@ Override protected void onDraw (Canvas canvas) {Paint paint = new Paint (); paint. setTextS Ize (20); paint. setColor (Color. GRAY); canvas. drawText ("input prompt text:", 10, getHeight ()/2 + 5, paint); super. onDraw (canvas) ;}} main. xml: [html] <? Xml version = "1.0" encoding = "UTF-8"?> <RelativeLayout xmlns: android = "http://schemas.android.com/apk/res/android" android: id = "@ + id/linearlayout" android: layout_width = "fill_parent" android: layout_height = "fill_parent" android: orientation = "horizontal"> <Button android: id = "@ + id/button2" android: layout_width = "80dp" android: layout_height = "80dp" android: layout_alignParentTop = "true" android: layout_centerHorizontal = "true" android: layout_marginTop = "150dp" android: onClick = "click" android: text = "Button"/> </RelativeLayout>