1.TextView
Here are just a few of the properties, and there are a lot of properties that need to be used again
<textview
Android:textsize= "24SP"// Text Size
Android:textcolor= "#00ff00"// text color
android:gravity= "Center"// arrangement Direction
Android:id= "@+id/txtmainone"
Android:text= "This is a regular activity interface"
Android:layout_width= "Match_parent"
android:layout_height= "Wrap_content"/>
2.Button
<button
Android:id= "@+id/btnmainone"
android:text= "button"
Android:layout_width= "Match_parent"
android:layout_height= "Wrap_content"/>
Adding events to a button in Java code can be handled uniformly by allowing the class to implement the interface View.onclicklistener
public class Mainactivity extends Activity implements View.onclicklistener {
The Listener event for the Bind button in the OnCreate method is the class itself
Button btnmainone= (button) Findviewbyid (R.id.btnmainone);
Btnmainone.setonclicklistener (this);
Other code ... Here's how to focus on the click button
@Override
public void OnClick(View v)
{
Switch (v.getid ())
{
Case R.id.btnmainone:
Writing logic
Break
Default
break;;
}
}
3.EditText
<edittext
Android:id= "@+id/txtmaintwo"
android:hint= "acts as a cue message "
android:maxlines= "2"//Limit text input box only 2 lines, not because of too much content to appear the control infinite elongated
Android:layout_width= "Match_parent"
android:layout_height= "Wrap_content"/>
Get the value in EditText
EditText txtmaintwo= (EditText) Findviewbyid (r.id.txtmaintwo);
String value=txtmaintwo.gettext (). toString ();
Toast.maketext (Mainactivity.this,value,toast.length_short). Show ();
4.ImageView
<imageview
Android:id= "@+id/imgmainone"
android:src= "@drawable/ic_launcher"// picture address
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"/>
ImageView imageview= (ImageView) Findviewbyid (R.id.imgmainone);
ImageView. Setimageresource (r.drawable.one);//Modify Picture
5.ProgressBar Display Progress
<progressbar
android:visibility= "visible"//all spaces have this familiarity, visible,invisible and gone, respectively, representing the display space, hiding the control but occupying the location, deleting the control directly
Android:id= "@+id/pgbmainone"
Android:layout_width= "Match_parent"
android:layout_height= "Wrap_content"
style= "@style/base.widget.appcompat.progressbar.horizontal"//set to horizontal performance
Android:background= "#ff5b7fff"//Background color
android:max= "Max"/>//maximum value
Code Control display
ProgressBar progressbar= (ProgressBar) Findviewbyid (R.id.pgbmainone);
if (progressbar.getvisibility ()==view.gone)
{
progressbar.setvisibility (view.visible);
}
Else
{
progressbar.setvisibility (view.gone);
}
Set the progress bar
int Progress=progressbar. getprogress ();
progress+=10;
ProgressBar. setprogress (progress);
6.Alertdialog
Alertdialog.builder dialog=new Alertdialog.builder (mainactivity.this);
Dialog.settitle ("hint message");
Dialog.setmessage ("Very important information");
Dialog.setcancelable (FALSE);
Dialog.setpositivebutton ("OK", new Dialoginterface.onclicklistener () {
@Override
public void OnClick (Dialoginterface dialog, int which) {
}
});
Dialog.setnegativebutton ("Cancel", new Dialoginterface.onclicklistener () {
@Override
public void OnClick (Dialoginterface dialog, int which) {
}
});
Dialog.show ();
7.ProgressDialog
Combining multi-threaded display
Final ProgressDialog Progressdialog=newProgressDialog(Mainactivity.this);
Progressdialog.settitle ("hint");//Set Caption
Progressdialog.setcanceledontouchoutside (false);//whether to return to the main screen in a blank space
Progressdialog.setmax (100);//set to the horizontal progress bar maximum value
Progressdialog.setmessage ("Prompt content information");//hint content
Progressdialog.setcancelable (false);//Whether to select the Cancel key to return
Progressdialog.setprogress (40);
Progressdialog.setprogressstyle (progressdialog.style_horizontal);//Set to Landscape progress
Progressdialog.seticon (R.drawable.one);//Set icon
Progressdialog.setbutton (dialoginterface.button_positive, "OK", new Dialoginterface.onclicklistener () {//Add button Event
@Override
public void OnClick (Dialoginterface dialog, int which) {
Toast.maketext (Mainactivity.this, "press button", Toast.length_long). Show ();
}
});
Progressdialog.setbutton (Dialoginterface.button_negative, "Cancel", new Dialoginterface.onclicklistener () {
@Override
public void OnClick (Dialoginterface dialog, int which) {
}
});
Progressdialog.show ();//Display
new Thread (new Runnable () {// Create multithreading
@Override
public void Run () {
TODO auto-generated Method Stub
int i = 0;
while (I < 100) {
try {
Thread.Sleep (200);
Update progress bar Progress, you can update progress bar progress in a child thread
ProgressDialog. Incrementprogressby (1);// Set progress bar add value
Dialog.incrementsecondaryprogressby (10)//two level progress bar update mode
i++;
} catch (Exception e) {
Todo:handle exception
}
}
ProgressDialog. Dismiss ();// Delete ProgressDialog when the progress bar has gone through
}
}). Start ();//Start multithreading
8. Layout: Common 4 kinds of layout linearlayout,relativelayout,framelayout
linearlayout: linear layout mode, android:orientation= "vertical" means vertical arrangement, android:orientation= " Horizontal"indicates horizontal arrangement
android:layout_gravity= "right"//sets the position of the control, when it is horizontal, only the vertical position can be set, when the vertical direction can only set the horizontal position.
When setting android:orientation= "horizontal" You can set the width of the control to 0:android:layout_width= "0DP"and then set the weight on the width of Android :layout_weight= "1" indicates the proportion occupied
relativelayout: Relative position layout, you can set the corresponding property setting relative to the parent element's coordinates or a control's coordinates
relative to parent element :
Layout_alignparentleft
Layout_alignparenttop
Layout_alignparentright
Layout_centerinparent
Layout_alignparentbottom
relative to a control :
android:layout_above= "@+id/btnbthree" //relative to the top of a control
android:layout_below= "@+id/btnbthree"//relative to a space below
android:layout_toleftof= "@+id/btnbthree"
android:layout_torightof= "@+id/btnbthree"
android:layout_tostartof= "@+id/btnbthree"
android:layout_toendof= "@+id/btnbthree"
Android:layout_alignbottom= "@+id/btnbthree"
android:layout_aligntop= "@+id/btnbthree"
android:layout_alignright= "@+id/btnbthree"
android:layout_alignleft= "@+id/btnbthree"
Android:layout_alignend= "@+id/btnbthree"
Android:layout_alignstart= "@+id/btnbthree"
framelayout: All controls will be positioned in the upper-left corner, overlapping, not common, but in the fragment section will appear
Tablelayout: Allows the control to be arranged in a tabular manner, not commonly used.
9. Custom Controls
First design a layout file, and then another page to introduce the interface has been designed:<include layout= "@layout/title"/>
If you are a custom control: first define a class to inherit to LinearLayout, and write the event of that class in the constructor
public class Titlelayout extends linearlayout {
Public Titlelayout (Context context,attributeset attrs)
{
Super (CONTEXT,ATTRS);
layoutinflater.from (context). Inflate (r.layout.title,this);
Button btntitleone= (button) Findviewbyid (R.id.title_back);
Btntitleone.setonclicklistener (New Onclicklistener () {
@Override
public void OnClick (View v) {
( activity) getcontext ()). Finish ();//Find your current Activity
}
});
Button btntitletwo= (button) Findviewbyid (R.id.title_edit);
Btntitletwo.setonclicklistener (New Onclicklistener () {
@Override
public void OnClick (View v) {
Toast.maketext (getcontext (),"You have selected the Edit button", Toast.length_short). Show ();
}
});
}
}
Start using the user control
<com.example.zhb.test2.titlelayout
Android:layout_width= "Match_parent"
android:layout_height= "Wrap_content" ></com.example.zhb.test2.TitleLayout>
Android Getting started to proficiency (iii)----UI interface