hsiao 7 年之前
父節點
當前提交
3edc33707e

+ 6
- 0
.idea/vcs.xml 查看文件

@@ -0,0 +1,6 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project version="4">
3
+  <component name="VcsDirectoryMappings">
4
+    <mapping directory="$PROJECT_DIR$" vcs="Git" />
5
+  </component>
6
+</project>

+ 3
- 0
lesson02/src/main/AndroidManifest.xml 查看文件

@@ -16,6 +16,9 @@
16 16
                 <category android:name="android.intent.category.LAUNCHER" />
17 17
             </intent-filter>
18 18
         </activity>
19
+        <activity android:name=".MessageActivity"></activity>
20
+        <activity android:name=".MicroAppsActivity"></activity>
21
+        <activity android:name=".UserCenterActivity"></activity>
19 22
     </application>
20 23
 
21 24
 </manifest>

+ 79
- 1
lesson02/src/main/java/io/hsiao/lesson02/MainActivity.java 查看文件

@@ -1,13 +1,91 @@
1 1
 package io.hsiao.lesson02;
2 2
 
3
-import android.support.v7.app.AppCompatActivity;
3
+import android.content.Intent;
4 4
 import android.os.Bundle;
5
+import android.support.v7.app.AppCompatActivity;
6
+import android.support.v7.widget.Toolbar;
7
+import android.util.Log;
8
+import android.view.Menu;
9
+import android.view.MenuItem;
10
+import android.widget.ArrayAdapter;
11
+import android.widget.ListView;
12
+import android.widget.SimpleAdapter;
13
+import android.widget.Toast;
14
+
15
+import java.text.SimpleDateFormat;
16
+import java.util.ArrayList;
17
+import java.util.Date;
18
+import java.util.HashMap;
19
+import java.util.List;
20
+import java.util.Map;
21
+import java.util.Objects;
5 22
 
6 23
 public class MainActivity extends AppCompatActivity {
7 24
 
25
+    private SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd hh:mm:ss");
26
+    private ListView listView;
27
+
8 28
     @Override
9 29
     protected void onCreate(Bundle savedInstanceState) {
10 30
         super.onCreate(savedInstanceState);
11 31
         setContentView(R.layout.activity_main);
32
+        Toolbar toolBar = (Toolbar) findViewById(R.id.toolbar);
33
+        setSupportActionBar(toolBar);
34
+        Log.i("youmap", "MainActivity创建完成");
35
+
36
+        this.createListView();
37
+    }
38
+
39
+    private void createListView() {
40
+        this.listView = (ListView) findViewById(R.id.main_listview);
41
+        this.listView.setAdapter(new SimpleAdapter(this, getData(), R.layout.home_list, new String[]{"title", "thumbnail", "date"}, new int[]{R.id.home_list_title, R.id.home_list_date, R.id.home_list_desc}));
42
+    }
43
+
44
+    private List<HashMap<String, Object>> getData() {
45
+        ArrayList list = new ArrayList();
46
+        for(int i=0;i<100;i++){
47
+            HashMap<String,String> map = new HashMap<>();
48
+            map.put("title","标题 "+i);
49
+            map.put("thumbnail","图片 "+i);
50
+            map.put("date", sdf.format(new Date()));
51
+
52
+            list.add(map);
53
+        }
54
+        return list;
55
+    }
56
+
57
+    @Override
58
+    public boolean onCreateOptionsMenu(Menu menu) {
59
+        getMenuInflater().inflate(R.menu.menu, menu);
60
+        return true;
61
+    }
62
+
63
+    @Override
64
+    public boolean onOptionsItemSelected(MenuItem item) {
65
+        Toast.makeText(this.getApplicationContext(), item.getTitle() + " " + item.getItemId(), Toast.LENGTH_LONG).show();
66
+        Intent intent = null;
67
+        switch (item.getItemId()) {
68
+            case R.id.menu_item_about:
69
+                intent = new Intent(this, MessageActivity.class);
70
+                break;
71
+            case R.id.menu_item_account:
72
+                intent = new Intent(this, UserCenterActivity.class);
73
+                break;
74
+            case R.id.menu_item_contacts:
75
+                intent = new Intent(this, MessageActivity.class);
76
+                break;
77
+            case R.id.menu_item_mapps:
78
+                intent = new Intent(this, MicroAppsActivity.class);
79
+                break;
80
+            case R.id.menu_item_message:
81
+                intent = new Intent(this, MessageActivity.class);
82
+                break;
83
+            case R.id.menu_item_search:
84
+                intent = new Intent(this, MessageActivity.class);
85
+                break;
86
+        }
87
+        startActivity(intent);
88
+
89
+        return true;
12 90
     }
13 91
 }

+ 14
- 0
lesson02/src/main/java/io/hsiao/lesson02/MessageActivity.java 查看文件

@@ -0,0 +1,14 @@
1
+package io.hsiao.lesson02;
2
+
3
+import android.app.Activity;
4
+import android.support.v7.app.AppCompatActivity;
5
+import android.os.Bundle;
6
+
7
+public class MessageActivity extends Activity {
8
+
9
+    @Override
10
+    protected void onCreate(Bundle savedInstanceState) {
11
+        super.onCreate(savedInstanceState);
12
+        setContentView(R.layout.activity_message);
13
+    }
14
+}

+ 13
- 0
lesson02/src/main/java/io/hsiao/lesson02/MicroAppsActivity.java 查看文件

@@ -0,0 +1,13 @@
1
+package io.hsiao.lesson02;
2
+
3
+import android.app.Activity;
4
+import android.os.Bundle;
5
+
6
+public class MicroAppsActivity extends Activity {
7
+
8
+    @Override
9
+    protected void onCreate(Bundle savedInstanceState) {
10
+        super.onCreate(savedInstanceState);
11
+        setContentView(R.layout.activity_micro_apps);
12
+    }
13
+}

+ 13
- 0
lesson02/src/main/java/io/hsiao/lesson02/UserCenterActivity.java 查看文件

@@ -0,0 +1,13 @@
1
+package io.hsiao.lesson02;
2
+
3
+import android.app.Activity;
4
+import android.os.Bundle;
5
+
6
+public class UserCenterActivity extends Activity {
7
+
8
+    @Override
9
+    protected void onCreate(Bundle savedInstanceState) {
10
+        super.onCreate(savedInstanceState);
11
+        setContentView(R.layout.activity_user_center);
12
+    }
13
+}

+ 15
- 12
lesson02/src/main/res/layout/activity_main.xml 查看文件

@@ -1,18 +1,21 @@
1 1
 <?xml version="1.0" encoding="utf-8"?>
2
-<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
-    xmlns:app="http://schemas.android.com/apk/res-auto"
4
-    xmlns:tools="http://schemas.android.com/tools"
2
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
5 3
     android:layout_width="match_parent"
6 4
     android:layout_height="match_parent"
7
-    tools:context="io.hsiao.lesson02.MainActivity">
5
+    android:orientation="vertical">
8 6
 
9
-    <TextView
10
-        android:layout_width="wrap_content"
7
+    <android.support.v7.widget.Toolbar
8
+        android:id="@+id/toolbar"
9
+        android:layout_width="match_parent"
11 10
         android:layout_height="wrap_content"
12
-        android:text="Hello World!"
13
-        app:layout_constraintBottom_toBottomOf="parent"
14
-        app:layout_constraintLeft_toLeftOf="parent"
15
-        app:layout_constraintRight_toRightOf="parent"
16
-        app:layout_constraintTop_toTopOf="parent" />
11
+        android:background="?attr/colorPrimary"
12
+        android:elevation="0dp"
13
+        android:minHeight="?attr/actionBarSize"
14
+        android:theme="?attr/actionBarTheme" />
17 15
 
18
-</android.support.constraint.ConstraintLayout>
16
+    <ListView
17
+        android:id="@+id/main_listview"
18
+        android:layout_width="match_parent"
19
+        android:layout_height="match_parent" />
20
+
21
+</LinearLayout>

+ 12
- 0
lesson02/src/main/res/layout/activity_message.xml 查看文件

@@ -0,0 +1,12 @@
1
+<?xml version="1.0" encoding="utf-8"?>
2
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
+    android:layout_width="match_parent"
4
+    android:layout_height="match_parent">
5
+
6
+    <TextView
7
+        android:id="@+id/textView3"
8
+        android:layout_width="wrap_content"
9
+        android:layout_height="wrap_content"
10
+        android:layout_weight="1"
11
+        android:text="消息" />
12
+</LinearLayout>

+ 14
- 0
lesson02/src/main/res/layout/activity_micro_apps.xml 查看文件

@@ -0,0 +1,14 @@
1
+<?xml version="1.0" encoding="utf-8"?>
2
+<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
+    xmlns:app="http://schemas.android.com/apk/res-auto"
4
+    xmlns:tools="http://schemas.android.com/tools"
5
+    android:layout_width="match_parent"
6
+    android:layout_height="match_parent"
7
+    tools:context="io.hsiao.youmap.MicroAppsActivity">
8
+
9
+    <TextView
10
+        android:id="@+id/textView5"
11
+        android:layout_width="wrap_content"
12
+        android:layout_height="wrap_content"
13
+        android:text="微应用" />
14
+</android.support.constraint.ConstraintLayout>

+ 12
- 0
lesson02/src/main/res/layout/activity_user_center.xml 查看文件

@@ -0,0 +1,12 @@
1
+<?xml version="1.0" encoding="utf-8"?>
2
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
+    android:layout_width="match_parent"
4
+    android:layout_height="match_parent">
5
+
6
+    <TextView
7
+        android:id="@+id/textView4"
8
+        android:layout_width="wrap_content"
9
+        android:layout_height="wrap_content"
10
+        android:layout_weight="1"
11
+        android:text="TextView" />
12
+</LinearLayout>

+ 41
- 0
lesson02/src/main/res/layout/home_list.xml 查看文件

@@ -0,0 +1,41 @@
1
+<?xml version="1.0" encoding="utf-8"?>
2
+
3
+
4
+<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
5
+    xmlns:app="http://schemas.android.com/apk/res-auto"
6
+    xmlns:tools="http://schemas.android.com/tools"
7
+    android:layout_width="match_parent"
8
+    android:layout_height="match_parent">
9
+
10
+
11
+    <TextView
12
+        android:id="@+id/home_list_title"
13
+        android:layout_width="wrap_content"
14
+        android:layout_height="wrap_content"
15
+        android:layout_weight="1"
16
+        android:text="@android:string/dialog_alert_title"
17
+        tools:layout_editor_absoluteY="0dp"
18
+        android:layout_marginLeft="0dp"
19
+        app:layout_constraintLeft_toLeftOf="parent" />
20
+
21
+    <TextView
22
+        android:id="@+id/home_list_date"
23
+        android:layout_width="wrap_content"
24
+        android:layout_height="wrap_content"
25
+        android:layout_weight="1"
26
+        android:text="date"
27
+        android:textAlignment="viewEnd"
28
+        app:layout_constraintRight_toRightOf="parent"
29
+        tools:layout_editor_absoluteY="0dp" />
30
+
31
+    <TextView
32
+        android:id="@+id/home_list_desc"
33
+        android:layout_width="wrap_content"
34
+        android:layout_height="wrap_content"
35
+        android:layout_marginTop="16dp"
36
+        android:layout_weight="1"
37
+        android:text="TextView"
38
+        app:layout_constraintTop_toBottomOf="@+id/home_list_title"
39
+        tools:layout_editor_absoluteX="0dp" />
40
+
41
+</android.support.constraint.ConstraintLayout>

+ 25
- 0
lesson02/src/main/res/menu/menu.xml 查看文件

@@ -0,0 +1,25 @@
1
+<menu xmlns:android="http://schemas.android.com/apk/res/android"
2
+    xmlns:app="http://schemas.android.com/apk/res-auto">
3
+
4
+    <item
5
+        android:id="@+id/menu_item_message"
6
+        android:title="消息"
7
+        app:showAsAction="always" />
8
+    <item
9
+        android:id="@+id/menu_item_mapps"
10
+        android:title="微应用"
11
+        app:showAsAction="always" />
12
+    <item
13
+        android:id="@+id/menu_item_about"
14
+        android:title="关于友图" />
15
+    <item
16
+        android:id="@+id/menu_item_account"
17
+        android:title="账户中心" />
18
+    <item
19
+        android:id="@+id/menu_item_contacts"
20
+        android:title="通讯录" />
21
+    <item
22
+        android:id="@+id/menu_item_search"
23
+        android:title="搜索"
24
+        app:showAsAction="always" />
25
+</menu>

+ 2
- 5
lesson02/src/main/res/values/styles.xml 查看文件

@@ -1,11 +1,8 @@
1 1
 <resources>
2 2
 
3 3
     <!-- Base application theme. -->
4
-    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
5
-        <!-- Customize your theme here. -->
6
-        <item name="colorPrimary">@color/colorPrimary</item>
7
-        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
8
-        <item name="colorAccent">@color/colorAccent</item>
4
+    <style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
5
+
9 6
     </style>
10 7
 
11 8
 </resources>

Loading…
取消
儲存