Android non-XML forms a way to dynamically generate and invoke pages _android

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.