国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

服務(wù)器之家:專注于服務(wù)器技術(shù)及軟件下載分享
分類導(dǎo)航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術(shù)|正則表達(dá)式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務(wù)器之家 - 編程語言 - Android - Android仿微信公眾號界面

Android仿微信公眾號界面

2022-03-02 15:18oxygen0106 Android

這篇文章主要為大家詳細(xì)介紹了Android仿微信公眾號界面,具有一定的參考價值,感興趣的小伙伴們可以參考一下

最近在做一個關(guān)于微信公眾平臺服務(wù)號的小項目,主要用來實現(xiàn)排隊叫號功能。一直都對微信公眾號開發(fā)比較好奇,于是趁這次機會仔細(xì)研究了一下公眾號的開發(fā)流程和邏輯架構(gòu)。

微信公眾平臺現(xiàn)在分為3類:訂閱號,服務(wù)號和企業(yè)號。其中,服務(wù)號和企業(yè)號的開放權(quán)限比較高,可以實現(xiàn)自定義菜單功能,調(diào)用攝像頭以及LBS等API。

基本通信架構(gòu)如圖:

Android仿微信公眾號界面

在項目的功能設(shè)計階段本想搭建一個服務(wù)號Demo用來展示,但微信服務(wù)號的認(rèn)證手續(xù)太麻煩,而且我也沒有那個資質(zhì)去開通服務(wù)號。于是打算自己做一個仿微信公眾號的基本界面,先實現(xiàn)菜單功能,避免開發(fā)初期的公眾號注冊,同時也方便展示。

先上效果圖:

Android仿微信公眾號界面

Android仿微信公眾號界面

Android仿微信公眾號界面

1. 界面布局

主界面布局四部分,由上到下依次是:標(biāo)題欄,消息列表,底部菜彈出的子菜單,底部菜單或輸入欄。

主界面基本框架main.xml代碼如下:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:id="@+id/main"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:background="#E4E4E4" >
 
  <!-- 消息列表 -->
 
  <ListView
    android:id="@+id/lv"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_marginBottom="50dp"
    android:layout_marginTop="10dp"
    android:cacheColorHint="#00000000"
    android:divider="#00000000"
    android:dividerHeight="20dp"
    android:scrollbars="none" >
  </ListView>
 
  <!-- 點擊底部菜單后彈出的子菜單 -->
 
  <LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    android:layout_marginBottom="50dp"
    android:orientation="horizontal" >
 
    <View
      android:layout_width="0dp"
      android:layout_height="wrap_content"
      android:layout_weight="0.5" />
 
    <LinearLayout
      android:id="@+id/pop_layout1"
      android:layout_width="0dp"
      android:layout_height="wrap_content"
      android:layout_gravity="bottom"
      android:layout_weight="1"
      android:orientation="vertical" >
    </LinearLayout>
 
    <LinearLayout
      android:id="@+id/pop_layout2"
      android:layout_width="0dp"
      android:layout_height="wrap_content"
      android:layout_gravity="bottom"
      android:layout_weight="1"
      android:orientation="vertical" >
    </LinearLayout>
 
    <LinearLayout
      android:id="@+id/pop_layout3"
      android:layout_width="0dp"
      android:layout_height="wrap_content"
      android:layout_gravity="bottom"
      android:layout_weight="1"
      android:orientation="vertical" >
    </LinearLayout>
  </LinearLayout>
   
  <!-- 底部菜單 -->
 
  <LinearLayout
    android:id="@+id/bottom_layout"
    android:layout_width="fill_parent"
    android:layout_height="50dp"
    android:layout_gravity="bottom"
    android:background="#00ffffff"
    android:orientation="vertical" >
 
    <LinearLayout
      android:id="@+id/bottom_menu_layout1"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:background="#ffffff"
      android:orientation="vertical" >
 
      <View
        android:layout_width="fill_parent"
        android:layout_height="1px"
        android:background="#A6A6A6" />
 
      <LinearLayout
        android:id="@+id/menu_layout"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:gravity="center"
        android:orientation="horizontal" >
 
        <ImageView
          android:id="@+id/keyboard"
          android:layout_width="0dp"
          android:layout_height="wrap_content"
          android:layout_marginBottom="5dp"
          android:layout_marginLeft="3dp"
          android:layout_marginRight="3dp"
          android:layout_marginTop="5dp"
          android:layout_weight="0.5"
          android:background="@drawable/keyboard" />
 
        <View
          android:layout_width="1px"
          android:layout_height="fill_parent"
          android:background="#A6A6A6" />
 
        <RelativeLayout
          android:id="@+id/btn1"
          android:layout_width="0dp"
          android:layout_height="fill_parent"
          android:layout_weight="1"
          android:background="@drawable/btn_selector" >
 
          <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_margin="5dp" >
 
            <TextView
              android:id="@+id/text1"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:layout_centerInParent="true"
              android:gravity="center"
              android:text="用戶綁定"
              android:textColor="#000000"
              android:textSize="16sp" />
 
            <ImageView
              android:layout_width="10dp"
              android:layout_height="10dp"
              android:layout_alignParentBottom="true"
              android:layout_alignParentRight="true"
              android:src="@drawable/more_icon"
              android:visibility="invisible" />
          </RelativeLayout>
        </RelativeLayout>
 
        <View
          android:layout_width="1px"
          android:layout_height="fill_parent"
          android:background="#A6A6A6" />
 
        <RelativeLayout
          android:id="@+id/btn2"
          android:layout_width="0dp"
          android:layout_height="fill_parent"
          android:layout_weight="1"
          android:background="@drawable/btn_selector" >
 
          <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_margin="5dp" >
 
            <TextView
              android:id="@+id/text2"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:layout_centerInParent="true"
              android:gravity="center"
              android:text="掃描簽到"
              android:textColor="#000000"
              android:textSize="16sp" />
 
            <ImageView
              android:layout_width="10dp"
              android:layout_height="10dp"
              android:layout_alignParentBottom="true"
              android:layout_alignParentRight="true"
              android:src="@drawable/more_icon"
              android:visibility="invisible" />
          </RelativeLayout>
        </RelativeLayout>
 
        <View
          android:layout_width="1px"
          android:layout_height="fill_parent"
          android:background="#A6A6A6" />
 
        <RelativeLayout
          android:id="@+id/btn3"
          android:layout_width="0dp"
          android:layout_height="fill_parent"
          android:layout_weight="1"
          android:background="@drawable/btn_selector" >
 
          <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_margin="5dp" >
 
            <TextView
              android:id="@+id/text3"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:layout_centerInParent="true"
              android:gravity="center"
              android:text="更多"
              android:textColor="#000000"
              android:textSize="16sp" />
 
            <ImageView
              android:layout_width="10dp"
              android:layout_height="10dp"
              android:layout_alignParentBottom="true"
              android:layout_alignParentRight="true"
              android:src="@drawable/more_icon"
              android:visibility="visible" />
          </RelativeLayout>
        </RelativeLayout>
      </LinearLayout>
    </LinearLayout>
  </LinearLayout>
 
</FrameLayout>

標(biāo)題欄title_bar.xml布局如下:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:orientation="horizontal" >
 
  <!-- 返回 -->
 
  <ImageView
    android:id="@+id/title_bar_back_btn"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_centerVertical="true"
    android:layout_marginLeft="10dip"
    android:src="@drawable/back" />
   
  <!-- 服務(wù)號名稱 -->
 
  <TextView
    android:id="@+id/my_setting_title_tv"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:text="騰訊招聘面試服務(wù)"
    android:textColor="#ffffff"
    android:textSize="20sp" />
   
  <!-- 服務(wù)號 -->
 
  <ImageView
    android:id="@+id/title_bar_my"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_centerVertical="true"
    android:layout_marginRight="10dip"
    android:src="@drawable/my" />
 
</RelativeLayout>

完成title_bar布局后,再在valuesstyles.xml添加自定義標(biāo)題欄主題

?
1
2
3
4
5
6
7
8
9
10
<!-- 自定義標(biāo)題欄背景顏色 -->
  <style name="CustomWindowTitleBackground">
    <item name="android:background">#32394A</item>
  </style>
 
  <!-- 自定義標(biāo)題欄主題 -->
  <style name="myTheme" parent="android:Theme">
    <item name="android:windowTitleSize">45dp</item>
    <item name="android:windowTitleBackgroundStyle">@style/CustomWindowTitleBackground</item>
</style>

消息列表的服務(wù)端消息item布局item_left.xml

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?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="horizontal" >
 
  <RelativeLayout
    android:layout_width="0dp"
    android:layout_height="fill_parent"
    android:layout_weight="4" >
    <ImageView
      android:id="@+id/server_image"
      android:layout_width="40dp"
      android:layout_height="40dp"
      android:layout_marginLeft="2dp"
      android:background="@drawable/qq"/>
    <TextView
      android:id="@+id/server_text"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_marginLeft="2dp"
      android:layout_toRightOf="@id/server_image"
      android:background="@drawable/text_bg_left1"
      android:gravity="center_vertical|left"
      android:textSize="16sp"
      android:textColor="#000000"/>
  </RelativeLayout>
 
  <View
    android:layout_width="0dp"
    android:layout_height="fill_parent"
    android:layout_weight="1" />
 
</LinearLayout>

消息列表的用戶消息item布局item_right.xml

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?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="horizontal" >
 
  <View
    android:layout_width="0dp"
    android:layout_height="fill_parent"
    android:layout_weight="1" />
 
  <RelativeLayout
    android:layout_width="0dp"
    android:layout_height="fill_parent"
    android:layout_weight="4" >
 
    <ImageView
      android:id="@+id/user_image"
      android:layout_width="40dp"
      android:layout_height="40dp"
      android:layout_alignParentRight="true"
      android:layout_marginRight="2dp"
      android:background="@drawable/qq" />
 
    <TextView
      android:id="@+id/user_text"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_marginRight="1dp"
      android:layout_toLeftOf="@id/user_image"
      android:background="@drawable/text_bg_right1"
      android:gravity="center_vertical|right"
      android:textColor="#000000"
      android:textSize="16sp" />
  </RelativeLayout>
 
</LinearLayout>

彈出的子菜單布局child_menu.xml如下:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/child_layout"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:background="#FFFFFF"
  android:gravity="bottom"
  android:orientation="vertical" >
 
  <RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >
 
    <Button
      android:id="@+id/test1"
      android:layout_width="wrap_content"
      android:layout_height="45dp"
      android:background="@drawable/btn_selector"
      android:paddingLeft="10dp"
      android:paddingRight="10dp"
      android:text="進(jìn)度查詢"
      android:textColor="#000000"
      android:textSize="16sp" />
 
    <View
      android:layout_width="wrap_content"
      android:layout_height="1px"
      android:layout_alignLeft="@id/test1"
      android:layout_alignRight="@id/test1"
      android:layout_below="@id/test1"
      android:background="#E4E4E4" />
  </RelativeLayout>
 
  <RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >
 
    <Button
      android:id="@+id/test1"
      android:layout_width="wrap_content"
      android:layout_height="45dp"
      android:background="@drawable/btn_selector"
      android:paddingLeft="10dp"
      android:paddingRight="10dp"
      android:text="使用幫助"
      android:textColor="#000000"
      android:textSize="16sp" />
 
    <View
      android:layout_width="wrap_content"
      android:layout_height="1px"
      android:layout_alignLeft="@id/test1"
      android:layout_alignRight="@id/test1"
      android:layout_below="@id/test1"
      android:background="#E4E4E4" />
  </RelativeLayout>
 
  <RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >
 
    <Button
      android:id="@+id/test1"
      android:layout_width="wrap_content"
      android:layout_height="45dp"
      android:background="@drawable/btn_selector"
      android:paddingLeft="10dp"
      android:paddingRight="10dp"
      android:text="聯(lián)系我們"
      android:textColor="#000000"
      android:textSize="16sp" />
 
    <View
      android:layout_width="wrap_content"
      android:layout_height="1px"
      android:layout_alignLeft="@id/test1"
      android:layout_alignRight="@id/test1"
      android:layout_below="@id/test1"
      android:background="#E4E4E4" />
  </RelativeLayout>
 
</LinearLayout>

由底部菜單切換到輸入框,輸入框bottom_menu_layout2.xml布局如下:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?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" >
 
  <LinearLayout
    android:id="@+id/bottom_menu_layout2"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#ffffff"
    android:orientation="vertical" >
 
    <View
      android:layout_width="fill_parent"
      android:layout_height="1px"
      android:background="#A6A6A6" />
 
    <LinearLayout
      android:id="@+id/menu_layout"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:gravity="center"
      android:orientation="horizontal" >
 
      <!-- 左側(cè)切換菜單按鈕 -->
 
      <ImageView
        android:id="@+id/menu"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginBottom="5dp"
        android:layout_marginLeft="3dp"
        android:layout_marginRight="3dp"
        android:layout_marginTop="5dp"
        android:layout_weight="0.5"
        android:background="@drawable/menu" />
 
      <View
        android:layout_width="1px"
        android:layout_height="fill_parent"
        android:background="#A6A6A6" />
 
      <RelativeLayout
        android:id="@+id/btn1"
        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:layout_margin="5dp"
        android:layout_weight="3"
        android:background="#ffffff" >
 
        <ImageView
          android:id="@+id/voice"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignParentLeft="true"
          android:layout_centerInParent="true"
          android:layout_marginLeft="5dp"
          android:src="@drawable/voice" />
 
 
        <!-- 右側(cè)“+”按鈕或發(fā)送按鈕 -->
 
        <Button
          android:id="@+id/add"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignParentRight="true"
          android:layout_centerInParent="true"
          android:layout_marginRight="1dp"
          android:background="@drawable/add"
          android:paddingBottom="5dp"
          android:paddingLeft="8dp"
          android:paddingRight="8dp"
          android:paddingTop="5dp"
          android:text=""
          android:textColor="#ffffff"
          android:textSize="14sp" />
 
        <!-- 輸入 -->
 
        <RelativeLayout
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:layout_centerInParent="true"
          android:layout_marginLeft="5dp"
          android:layout_marginRight="5dp"
          android:layout_toLeftOf="@id/add"
          android:layout_toRightOf="@id/voice" >
 
          <EditText
            android:id="@+id/input_text"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:background="#00000000"
            android:gravity="bottom"
            android:paddingLeft="2dp"
            android:paddingRight="2dp"
            android:text=""
            android:textColor="#000000"
            android:textSize="16sp" />
 
          <View
            android:layout_width="fill_parent"
            android:layout_height="1px"
            android:layout_below="@id/input_text"
            android:layout_marginTop="10dp"
            android:background="#A6A6A6" />
        </RelativeLayout>
      </RelativeLayout>
    </LinearLayout>
  </LinearLayout>
 
</LinearLayout>

2. 代碼實現(xiàn)

MainActivity.java

 

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
package com.example.wxdemo;
 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnFocusChangeListener;
import android.view.ViewGroup;
import android.view.Window;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
 
public class MainActivity extends Activity implements View.OnClickListener {
 
  private LinearLayout bottomLayout;// 底部菜單父框架
  private LinearLayout bottomMenuLayout1;// 底部菜單布局
  private LinearLayout bottomMenuLayout2;// 底部輸入框布局
  private RelativeLayout btn1;// “用戶綁定”按鈕布局
  private RelativeLayout btn2;// “掃描簽到”按鈕布局
  private RelativeLayout btn3;// “更多”按鈕布局
  private LinearLayout popLayout1;
  private LinearLayout popLayout2;
  private LinearLayout popLayout3;// 彈出的子菜單父框架布局
  private LinearLayout childLayout;// “更多”按鈕的子菜單
  private ListView lv;
  private MyAdapter adapter;
  private List<Map<String, String>> listData = new ArrayList<Map<String, String>>();
 
  private ImageView keyboard;// 底部鍵盤切換圖標(biāo)
  private ImageView menu;// 底部菜單切換圖標(biāo)
  private Button send;// 發(fā)送按鈕
  private EditText inputText;// 輸入框
 
  private boolean open = true;// 子菜單填充狀態(tài)標(biāo)記
  private boolean flag = false;// 子菜單顯示狀態(tài)標(biāo)記
  private boolean bind = false;// 用戶綁定狀態(tài)標(biāo)記
 
  private Animation animEnter;// 底部菜單進(jìn)入動畫
  private Animation animExit;// 底部菜單退出動畫
 
  private View view;
  private View view2;
  private LayoutInflater inflater;
 
  private int myID = 0;
 
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
    setContentView(R.layout.main);
    getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
        R.layout.title_bar);// 自定義標(biāo)題欄
 
    inflater = MainActivity.this.getLayoutInflater();
 
    popLayout1 = (LinearLayout) findViewById(R.id.pop_layout1);
    popLayout2 = (LinearLayout) findViewById(R.id.pop_layout2);
    popLayout3 = (LinearLayout) findViewById(R.id.pop_layout3);
 
    bottomLayout = (LinearLayout) findViewById(R.id.bottom_layout);
    bottomMenuLayout1 = (LinearLayout) findViewById(R.id.bottom_menu_layout1);
 
    keyboard = (ImageView) findViewById(R.id.keyboard);
    btn1 = (RelativeLayout) findViewById(R.id.btn1);
    btn2 = (RelativeLayout) findViewById(R.id.btn2);
    btn3 = (RelativeLayout) findViewById(R.id.btn3);
 
    lv = (ListView) findViewById(R.id.lv);
 
    btn1.setOnClickListener(this);
    btn2.setOnClickListener(this);
    btn3.setOnClickListener(this);
    keyboard.setOnClickListener(this);
 
    adapter = new MyAdapter(this, listData);
    lv.setAdapter(adapter);
 
  }
 
  @Override
  public void onClick(View v) {
    // TODO Auto-generated method stub
    int id = v.getId();
    switch (id) {
    case R.id.btn1:
      btn1Click();
      break;
    case R.id.btn2:
      break;
    case R.id.btn3:
      btn3Click();
      break;
    case R.id.keyboard:
      keyboardClick();
      break;
    case R.id.menu:
      menuClick();
      break;
    case R.id.add:
      sendClick();
      break;
    default:
      break;
    }
  }
 
  public void btn1Click() {// 用戶綁定
    Map<String, String> map = new HashMap<String, String>();
    map.put("type", "0");
    if (!bind) {
      map.put("text", "請輸入您的手機號或簡歷ID進(jìn)行帳號綁定,綁定成功后才能進(jìn)行簽到。");
    } else {
      map.put("text", "帳號已綁定成功,請您準(zhǔn)時簽到。");
    }
    listData.add(map);
    adapter.notifyDataSetChanged();
  }
 
  public void btn2Click() {// 掃描簽到
    // TODO
  }
 
  public void btn3Click() {// 更多
    if (open == true) {
      view = inflater.inflate(R.layout.child_menu, popLayout3, true);
      childLayout = (LinearLayout) view.findViewById(R.id.child_layout);
      open = false;
    }
 
    if (flag == false) {
      flag = true;
      childLayout.setVisibility(View.VISIBLE);
    } else {
      flag = false;
      childLayout.setVisibility(View.GONE);
    }
  }
 
  public void keyboardClick() {//點擊鍵盤按鈕,由底部菜單切換為底部輸入
    view2 = inflater.inflate(R.layout.bottom_menu_layout2, bottomLayout,
        true);
    bottomMenuLayout2 = (LinearLayout) view2
        .findViewById(R.id.bottom_menu_layout2);
    animEnter = AnimationUtils.loadAnimation(MainActivity.this,
        R.anim.my_pop_enter_anim);
    animExit = AnimationUtils.loadAnimation(MainActivity.this,
        R.anim.my_pop_exit_anim);
    animEnter.setStartOffset(200);
    bottomMenuLayout1.startAnimation(animExit);
    bottomMenuLayout1.setVisibility(View.GONE);
    bottomMenuLayout2.startAnimation(animEnter);
    bottomMenuLayout2.setVisibility(View.VISIBLE);
    menu = (ImageView) view2.findViewById(R.id.menu);
    inputText = (EditText) view2.findViewById(R.id.input_text);
    send = (Button) view2.findViewById(R.id.add);
    menu.setOnClickListener(this);
    send.setOnClickListener(this);
    inputClick();
  }
 
  public void menuClick() {//點擊菜單按鈕,由底部輸入框切換為底部菜單
    bottomMenuLayout2.startAnimation(animExit);
    bottomMenuLayout2.setVisibility(View.GONE);
    bottomMenuLayout1.startAnimation(animEnter);
    bottomMenuLayout1.setVisibility(View.VISIBLE);
  }
 
  public void inputClick() {
    inputText.setOnFocusChangeListener(new OnFocusChangeListener() {
 
      @Override
      public void onFocusChange(View v, boolean hasFocus) {
        // TODO Auto-generated method stub
        if (hasFocus) {
          send.setBackgroundResource(R.drawable.send_btn_bg);
          send.setText("發(fā)送");
        } else {
          send.setBackgroundResource(R.drawable.add);
          send.setText(" ");
        }
      }
    });
  }
 
  public void sendClick() {
    String text = inputText.getEditableText().toString();
    inputText.setText("");
    if (text != null && (!text.equals(""))) {
      Map<String, String> map;
      map = new HashMap<String, String>();
      map.put("type", "1");// 消息類型,服務(wù)端為0,用戶為1
      map.put("text", text);
      listData.add(map);
 
      map = new HashMap<String, String>();
      map.put("type", "0");
      map.put("text", "帳號已綁定成功,請您準(zhǔn)時簽到。");
      listData.add(map);
      adapter.notifyDataSetChanged();
      bind = true;
    }
  }
 
  private class MyAdapter extends BaseAdapter {
    public List<Map<String, String>> list;
    private Context context;
    private int type;
    private ListView listView;
 
    public MyAdapter(Context context, List<Map<String, String>> list) {
      this.context = context;
      this.list = list;
    }
 
    @Override
    public int getCount() {
      // TODO Auto-generated method stub
      return list.size();
    }
 
    @Override
    public Object getItem(int position) {
      // TODO Auto-generated method stub
      return list.get(position);
    }
 
    @Override
    public long getItemId(int position) {
      // TODO Auto-generated method stub
      return position;
    }
 
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
      // TODO Auto-generated method stub
      ViewHolder viewHolder = null;
      Map<String, String> map = (Map<String, String>) list.get(position);
      if (map.get("type").equals("0")) {// 服務(wù)端
        if (convertView == null) {
          convertView = inflater.inflate(R.layout.item_left, parent,
              false);
          viewHolder = new ViewHolder();
          viewHolder.mTextView = (TextView) convertView
              .findViewById(R.id.server_text);
          viewHolder.mImageView = (ImageView) convertView
              .findViewById(R.id.server_image);
          convertView.setTag(viewHolder);
        } else {
          viewHolder = (ViewHolder) convertView.getTag();
        }
 
        viewHolder.mTextView.setText(map.get("text"));
 
      } else {// 用戶
        if (convertView == null) {
          convertView = inflater.inflate(R.layout.item_right, parent,
              false);
          viewHolder = new ViewHolder();
          viewHolder.mTextView = (TextView) convertView
              .findViewById(R.id.user_text);
          viewHolder.mImageView = (ImageView) convertView
              .findViewById(R.id.user_image);
          convertView.setTag(viewHolder);
        } else {
          viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.mTextView.setText(map.get("text"));
      }
 
      return convertView;
    }
 
  }
 
  private final class ViewHolder {
    TextView mTextView;
    ImageView mImageView;
  }
 
}

以上就是實現(xiàn)仿微信服務(wù)號的主要代碼,菜單功能并沒用完全實現(xiàn),可根據(jù)實際情況和需要進(jìn)行添加。同時還需注意的是,底部菜單最多為3個,每個名稱限制在7個字符,包含的子菜單最多只能有5個。

原文鏈接:https://blog.csdn.net/oxygen0106/article/details/40513801

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 精品乱码一区二区三四区 | 国产精品久久久久久久久久久久冷 | 国产日韩精品视频 | 欧美日韩一区二区三区在线观看 | 中文字幕高清免费日韩视频在线 | 国产二区视频 | 免费观看毛片 | 久久久91精品国产一区二区三区 | 欧美成年网站 | 国产精品久久久久久久久久ktv | 日韩美女毛片 | 日日操夜夜操天天操 | 亚洲免费视频网站 | 伊人伊成久久人综合网站 | 久久天天躁狠狠躁夜夜躁2014 | 中文字幕不卡在线观看 | 黄视频入口 | 玖玖色资源 | 国产a√ | 日韩在线资源 | 成人在线欧美 | 视频一区二区中文字幕 | 日日夜夜精品 | 三区视频| 伊人久久综合影院 | 国产美女精品一区二区三区 | 亚洲一区二区三 | 成人性大片免费观看网站 | 婷婷色综合 | 午夜成人免费视频 | 欧美成人a| 午夜在线小视频 | 高清一区二区三区 | 欧美精品1区2区3区 欧洲一区在线 | 色在线免费观看 | 久久久99精品免费观看 | 亚洲欧美综合 | 91尤物网站网红尤物福利 | 成人影院www在线观看 | 免费在线观看一区二区 | 国产精品久久久久久久一区探花 |