|
| 1 | +[source code] Android Development Tutorials - 11 & 12 - User Interface |
| 2 | + |
| 3 | +***** Main Activity.java |
| 4 | +package your.package.name |
| 5 | + |
| 6 | +import android.support.v7.app.AppCompatActivity; |
| 7 | +import android.os.Bundle; |
| 8 | +import android.view.Menu; |
| 9 | +import android.view.MenuItem; |
| 10 | + |
| 11 | +public class MainActivity extends AppCompatActivity { |
| 12 | + |
| 13 | + @Override |
| 14 | + protected void onCreate(Bundle savedInstanceState) { |
| 15 | + super.onCreate(savedInstanceState); |
| 16 | + setContentView(R.layout.activity_main); |
| 17 | + } |
| 18 | + |
| 19 | + @Override |
| 20 | + public boolean onCreateOptionsMenu(Menu menu) { |
| 21 | + // Inflate the menu; this adds items to the action bar if it is present. |
| 22 | + getMenuInflater().inflate(R.menu.menu_main, menu); |
| 23 | + return true; |
| 24 | + } |
| 25 | + |
| 26 | + @Override |
| 27 | + public boolean onOptionsItemSelected(MenuItem item) { |
| 28 | + // Handle action bar item clicks here. The action bar will |
| 29 | + // automatically handle clicks on the Home/Up button, so long |
| 30 | + // as you specify a parent activity in AndroidManifest.xml. |
| 31 | + int id = item.getItemId(); |
| 32 | + |
| 33 | + //noinspection SimplifiableIfStatement |
| 34 | + if (id == R.id.action_settings) { |
| 35 | + return true; |
| 36 | + } |
| 37 | + |
| 38 | + return super.onOptionsItemSelected(item); |
| 39 | + } |
| 40 | +} |
| 41 | + |
| 42 | + |
| 43 | +***** activity_main.xml |
| 44 | + |
| 45 | +<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" |
| 46 | + xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" |
| 47 | + android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin" |
| 48 | + android:paddingRight="@dimen/activity_horizontal_margin" |
| 49 | + android:paddingTop="@dimen/activity_vertical_margin" |
| 50 | + android:paddingBottom="@dimen/activity_vertical_margin" |
| 51 | + tools:context="glwhitney.info.nbvideos11_12.MainActivity"> |
| 52 | + |
| 53 | + <TextView |
| 54 | + android:layout_width="wrap_content" |
| 55 | + android:layout_height="wrap_content" |
| 56 | + android:textAppearance="?android:attr/textAppearanceLarge" |
| 57 | + android:text="@string/SignInTitle" |
| 58 | + android:id="@+id/textView" |
| 59 | + android:layout_alignParentTop="true" |
| 60 | + android:layout_alignParentLeft="true" |
| 61 | + android:layout_alignParentStart="true" |
| 62 | + android:singleLine="true"/> |
| 63 | + |
| 64 | + <EditText |
| 65 | + android:layout_width="wrap_content" |
| 66 | + android:layout_height="wrap_content" |
| 67 | + android:inputType="textEmailAddress" |
| 68 | + android:ems="10" |
| 69 | + android:id="@+id/editText" |
| 70 | + android:layout_below="@+id/textView" |
| 71 | + android:layout_centerHorizontal="true" |
| 72 | + android:layout_marginTop="36dp" |
| 73 | + android:width="320dp"/> |
| 74 | + |
| 75 | + <EditText |
| 76 | + android:layout_width="wrap_content" |
| 77 | + android:layout_height="wrap_content" |
| 78 | + android:inputType="textPassword" |
| 79 | + android:ems="10" |
| 80 | + android:id="@+id/editText2" |
| 81 | + android:layout_marginTop="45dp" |
| 82 | + android:layout_below="@+id/editText" |
| 83 | + android:layout_alignLeft="@+id/editText" |
| 84 | + android:layout_alignStart="@+id/editText" |
| 85 | + android:width="320dp"/> |
| 86 | + |
| 87 | + <Button |
| 88 | + android:layout_width="wrap_content" |
| 89 | + android:layout_height="wrap_content" |
| 90 | + android:text="@string/SignInButtonText" |
| 91 | + android:id="@+id/button" |
| 92 | + android:layout_centerVertical="true" |
| 93 | + android:layout_centerHorizontal="true" /> |
| 94 | +</RelativeLayout> |
| 95 | + |
| 96 | +***** strings.xml |
| 97 | + |
| 98 | +<resources> |
| 99 | + <string name="app_name">NB Videos 11_12</string> |
| 100 | + <string name="title_activity_main">MainActivity</string> |
| 101 | + |
| 102 | + <string name="hello_world">Hello world!</string> |
| 103 | + <string name="action_settings">Settings</string> |
| 104 | + <string name="SignInTitle">Sign In</string> |
| 105 | + <string name="SignInButtonText">Log In</string> |
| 106 | +</resources> |
0 commit comments