1. All controls are sub-classes of view, the basic control is mainly button,textview,edittext,checkbox and so on.
2. In general, we can add controls to the interface by modifying the files in the layout res/layout/activity_main.xml
The display results are as follows:
Here is how we do it, first of all activity_main.xml is actually a display interface, we need our program to show what kind of control, can be added here.
The code is as follows:
<relativelayout xmlns:android= "http://schemas.android.com/apk/res/ Android "
xmlns:tools=" Http://schemas.android.com/tools "
android:layout_width=" Match_parent "
android:layout_height=" match_parent "
android:paddingbottom=" @dimen /activity_vertical_margin "
android:paddingleft=" @dimen/activity_horizontal_margin "
android:paddingright= "@dimen/activity_horizontal_margin"
android:paddingtop= "@dimen/ Activity_vertical_margin "
tools:context=". Mainactivity
<textview
Android:id= "+id/mytextview"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:text= "Hello World"/>
</RelativeLayout>
At the same time, we can also use code to achieve this effect. Find the Java source file Mainactivity.java below src, find the OnCreate method, add the code here, but the code needs to be added to Setcontentview (R.layout.activity_main); This code means to load Activity_main.xml. So we need to be able to manipulate the controls inside the interface after the interface is loaded. The code is as follows, note the red font:
public class Mainactivity extends Activity
{
Private TextView Mytextview;
@Override
protected void OnCreate (Bundle savedinstancestate)
{
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_main);
Mytextview = (TextView) Findviewbyid (R.id.mytextview);
Mytextview.settext ("Hello World");
}
Android Tutorial (ii)--use of basic control TextView