Android development-simple login interface and Android login interface
Use the <EditText/> <TextView> <ImageButton/> component xml to develop the interface, and use findViewById and OnClickListener to bind events to the background:
Use the <RadioGroup> and <RadioButton> components to implement a single worker
The Code is as follows:
Xml code:
<? Xml version = "1.0" encoding = "UTF-8"?> <LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android"
Android: layout_width = "match_parent"
Android: layout_height = "match_parent"
Android: orientation = "vertical">
<! -- Account input -->
<TextView
Android: id = "@ + id/text01"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: text = "@ string/user"
/>
<EditText
Android: id = "@ + id/edt01"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: hint = "@ string/input"
Android: textSize = "15sp"
Android: layout_marginTop = "20dp"
/>
<! -- Password Input -->
<TextView
Android: id = "@ + id/text02"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: text = "@ string/password"
/>
<EditText
Android: id = "@ + id/edt02"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: hint = "@ string/passw"
Android: textSize = "15sp"
Android: layout_marginTop = "20dp"
Android: inputType = "numberPassword"
/>
<! -- Singleton Application -->
<RadioGroup
Android: id = "@ + id/group"
Android: orientation = "horizontal"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
>
<RadioButton
Android: id = "@ + id/rb1"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "@ string/man"
/>
<RadioButton
Android: id = "@ + id/rb2"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "@ string/woman"
Android: checked = "true"
/>
</RadioGroup>
<! -- Login button -->
<Button
Android: id = "@ + id/submit_btn"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "@ string/submit"
Android: layout_gravity = "center"
Android: background = "@ drawable/anydo"
/>
</LinearLayout>
Java code:
Package com. example. login;
Import android. OS. Bundle;
Import android. app. Activity;
Import android. view. View;
Import android. view. View. OnClickListener;
Import android. widget. Button;
Import android. widget. EditText;
Import android. widget. Toast;
Public class MainActivity extends Activity {
Private EditText ed01;
Private EditText ed02;
Private Button submit;
Private String results1;
Private String results2;
@ Override
Protected void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
SetContentView (R. layout. main );
// Obtain the input box, button, and text box controls in the layout file.
Ed01 = (EditText) this. findViewById (R. id. edt01 );
Ed02 = (EditText) this. findViewById (R. id. edt02 );
Submit = (Button) this. findViewById (R. id. submit_btn );
// Add a click event for the button
Submit. setOnClickListener (new OnClickListener (){
Public void onClick (View v ){
// Obtain the content entered in the input box
Results1 = ed01.getText (). toString ();
Results2 = ed02.getText (). toString ();
// Determine the account and password entered;
If (results1.equals ("android") & amp; results2.equals ("2016 ")){
Toast. makeText (MainActivity. this, R. string. login, Toast. LENGTH_LONG). show ();
} Else {
Toast. makeText (MainActivity. this, R. string. failed, Toast. LENGTH_LONG). show ();
}
}
});
}
}