SHOW:
|
|
- or go back to the newest paste.
| 1 | MainActivity.java | |
| 2 | ============================= | |
| 3 | package com.example.teacher.mytasks; | |
| 4 | ||
| 5 | import android.support.v7.app.AppCompatActivity; | |
| 6 | import android.os.Bundle; | |
| 7 | import android.widget.EditText; | |
| 8 | ||
| 9 | public class MainActivity extends AppCompatActivity {
| |
| 10 | EditText txtUser,txtPass; | |
| 11 | ||
| 12 | @Override | |
| 13 | protected void onCreate(Bundle savedInstanceState) {
| |
| 14 | super.onCreate(savedInstanceState); | |
| 15 | setContentView(R.layout.activity_main); | |
| 16 | setPointer(); | |
| 17 | } | |
| 18 | ||
| 19 | private void setPointer() {
| |
| 20 | txtUser=findViewById(R.id.txtUser); | |
| 21 | txtPass=findViewById(R.id.txtPass); | |
| 22 | //how to get data from EditText | |
| 23 | ||
| 24 | String userName=txtUser.getText().toString(); | |
| 25 | } | |
| 26 | } | |
| 27 | ||
| 28 | string.xml | |
| 29 | ================== | |
| 30 | <resources> | |
| 31 | <string name="app_name">MyTasks</string> | |
| 32 | <string name="userName">Enter your user name..</string> | |
| 33 | <string name="userPass">Enter your password...</string> | |
| 34 | <string name="login">Login</string> | |
| 35 | <string name="register">Register</string> | |
| 36 | </resources> | |
| 37 | ||
| 38 | ||
| 39 | activity_main.xml | |
| 40 | ======================= | |
| 41 | <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
| 42 | android:layout_width="match_parent" | |
| 43 | android:layout_height="match_parent" | |
| 44 | android:orientation="vertical" | |
| 45 | android:layout_margin="16dp"> | |
| 46 | ||
| 47 | <!-- place for logo --> | |
| 48 | <LinearLayout | |
| 49 | android:layout_width="match_parent" | |
| 50 | android:layout_height="match_parent" | |
| 51 | android:layout_weight="1" | |
| 52 | android:orientation="vertical" | |
| 53 | android:gravity="center"> | |
| 54 | <TextView | |
| 55 | android:layout_width="wrap_content" | |
| 56 | android:layout_height="wrap_content" | |
| 57 | android:text="MY TASK" | |
| 58 | android:textSize="64sp"/> | |
| 59 | </LinearLayout> | |
| 60 | ||
| 61 | <!-- place for user input --> | |
| 62 | <LinearLayout | |
| 63 | android:layout_width="match_parent" | |
| 64 | android:layout_height="match_parent" | |
| 65 | android:layout_weight="1" | |
| 66 | android:orientation="vertical" | |
| 67 | android:gravity="center"> | |
| 68 | <EditText | |
| 69 | android:layout_width="match_parent" | |
| 70 | android:layout_height="wrap_content" | |
| 71 | android:hint="@string/userName" | |
| 72 | android:id="@+id/txtUser"/> | |
| 73 | <EditText | |
| 74 | android:layout_width="match_parent" | |
| 75 | android:layout_height="wrap_content" | |
| 76 | android:hint="@string/userPass" | |
| 77 | android:inputType="textPassword" | |
| 78 | android:layout_marginTop="20dp" | |
| 79 | android:id="@+id/txtPass"/> | |
| 80 | </LinearLayout> | |
| 81 | ||
| 82 | <!-- place for buttons--> | |
| 83 | <LinearLayout | |
| 84 | android:layout_width="match_parent" | |
| 85 | android:layout_height="match_parent" | |
| 86 | android:layout_weight="1" | |
| 87 | android:orientation="horizontal" | |
| 88 | android:gravity="top"> | |
| 89 | <Button | |
| 90 | android:layout_width="match_parent" | |
| 91 | android:layout_height="wrap_content" | |
| 92 | android:text="@string/register" | |
| 93 | android:textColor="#ffffff" | |
| 94 | android:background="#009fff" | |
| 95 | android:textSize="22sp" | |
| 96 | android:layout_weight="1" | |
| 97 | android:layout_margin="20dp" | |
| 98 | android:id="@+id/btnRegister"/> | |
| 99 | <Button | |
| 100 | android:layout_width="match_parent" | |
| 101 | android:layout_height="wrap_content" | |
| 102 | android:text="@string/login" | |
| 103 | android:textColor="#ffffff" | |
| 104 | android:background="#009fff" | |
| 105 | android:textSize="22sp" | |
| 106 | android:layout_weight="1" | |
| 107 | android:layout_margin="20dp" | |
| 108 | android:id="@+id/btnLogin"/> | |
| 109 | </LinearLayout> | |
| 110 | ||
| 111 | </LinearLayout> |