This article describes the Android non-XML form of dynamically generating, calling pages. Share to everyone for your reference. The specific analysis is as follows:
The problem is this: instead of building a page with XML, we use a program to build a new page and add a variety of controls to the page.
First, build a new page:
① adds a class to the SRC directory named Signpage
② add an activity to the Androidmainfest.xml:
<activity android:name= "Com.example.stest.SignPage"/>
Note that this sentence is added to indicate that the Signpage page is a subpage for the home page call to start.
③ opens the Sighpage.java, adds a edittext to it, and modifies the location:
import android.os.Bundle; import android.app.Activity; import Android.graphics.Color;
Import android.view.*;
Import android.widget.*;
Import Android.widget.RelativeLayout.LayoutParams; public class Signpagea extends activity{@Override protected void onCreate (Bundle savedinstancestate) {super.oncreate
(savedinstancestate);
Relativelayout main = new Relativelayout (this);
Add this to be freely placed//control position Main.setbackgroundcolor (0xFFFFFFFF);
Setcontentview (main);
EditText emailedittext=new EditText (this);
Layoutparams params = new Layoutparams (layoutparams.wrap_content,layoutparams.wrap_content);
This sentence must be written, so used to get EditText objects, do not write will be wrong params.leftmargin=50;
params.topmargin=50;
Emailedittext.sethint ("Email");
Emailedittext.settextcolor (Color.Black);
Emailedittext.setgravity (Gravity.top);
Emailedittext.setrawinputtype (0x00000021);
0x00000081 PASSWORD Main.addview (emailedittext, params); }
}
④ adds a button to the main page, and the button event is as follows:
Intent intent=new Intent (mainactivity.this,signpagea.class);
StartActivity (intent);
Finish ();
Call Child page
I hope this article will help you with your Android program.