Android高效率编码-细节,控件,架包,功能,工具,开源汇总
2016-12-08 15:36
375 查看
Android高效率编码-细节,控件,架包,功能,工具,开源汇总
版权声明:本文为博主原创文章,博客地址:http://blog.csdn.net/qq_26787115,未经博主允许不得转载。其实写博客的初衷也并不是说什么分享技术,毕竟咱还只是个小程序员,最大的目的就是对自我的知识积累,以后万一编码的时候断片了,也可以翻出来看看,这样子对自己也有好处,所以今天就汇总一下一些需要的东西。多图来了,加油!
一.游戏
小熊打字,我刚接触电脑练习打字的时候用到的
下载地址:http://download.csdn.net/detail/qq_26787115/9365721
二.色彩
这张颜色表上的颜色都太赞了
三.控件
1.TextView
//禁止换行 android:singleLine="true"1
2
1
2
//字体滚动 <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:singleLine="true" android:ellipsize="marquee" android:marqueeRepeatLimit="marquee_forever" android:focusable="true" android:focusableInTouchMode="true" />1
2
3
4
5
6
7
8
9
10
1
2
3
4
5
6
7
8
9
10
文本添加下划线
2.EditText
//只接收数字类型 android:numeric="integer" //只接收电话类型 android:phoneNumber="true" //密码效果 android:password="true"1
2
3
4
5
6
1
2
3
4
5
6
3.LinearLayout
各种属性
4.RelativeLayout
各种属性
5.Button
扁平的按钮xml写法
6.WebView
加载网页
7.RatiBar评分条
评分
8.ListView
基本写法
ArrayAdapter写法
SimpleAdapter写法
9.ToggleButton
ToggleButton更换主题
10.Spinner
布局
代码
11.Dialog
属性
用法
12.AutoCompleteTextView
AutoCompleteTextView
MultiAutoCompleteTextView
13.TabHost
布局
Activity
TabHostActivity自定义Title字体颜色等
14.Menu
菜单
15.String的一些常用方法
四.基础动画
1.缩放
2.透明
3.旋转
4.移动
5.混合
6.动画监听事件
五.功能(有些需要权限,自行添加)
1.拨号
第一种方法
第二种方法
2.SeekBar进度条
3.沉浸式状态栏
放在onCreate()方法里
4.隐藏ActionBar
getActionBar().hide();1
1
5.屏蔽返回键
6.按两次退出
方法1
方法2
private long exitTime = 0;1
1
7.拍照
8.分享
调用系统的分享功能
9.播放音乐
对应的功能,比如停止时stop();
10.ViewPager
11.获取软件版本号
12.检查SD卡状态
13.手机震动
14.跳转短信
15.头像选择
16.获取系统电量
17.下载
18.重启
root
19.关机
root
20.子线程网络下载图片
21.获取手机各种信息
效果图
直接上代码
注意添加各种权限
activity_main.xml
<?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:background="@android:color/white" android:orientation="vertical" > <RelativeLayout android:id="@+id/tab1_rl" android:layout_width="match_parent" android:layout_height="51dp" android:background="#34c083" > <TextView android:id="@+id/tab1_btn01" android:layout_width="wrap_content" android:layout_height="51dp" android:layout_centerHorizontal="true" android:background="@null" android:gravity="center" android:text="手机信息" android:textColor="@android:color/white" android:textSize="20dp" /> <Button android:id="@+id/btn_back" android:layout_width="wrap_content" android:layout_height="51dp" android:layout_alignParentLeft="true" android:background="@drawable/back" /> </RelativeLayout> <LinearLayout android:layout_width="fill_parent" android:layout_height="40dp" android:background="@android:color/white" android:gravity="center_vertical" android:orientation="horizontal" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="20dp" android:text="IP:" /> <TextView android:id="@+id/tv1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="测试" /> </LinearLayout> <TextView android:layout_width="fill_parent" android:layout_height="1dp" android:background="#aeaea9" /> <LinearLayout android:layout_width="fill_parent" android:layout_height="40dp" android:background="@android:color/white" android:gravity="center_vertical" android:orientation="horizontal" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="20dp" android:text="MAC地址:" /> <TextView android:id="@+id/tv2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="测试" /> </LinearLayout> <TextView android:layout_width="fill_parent" android:layout_height="1dp" android:background="#aeaea9" /> <LinearLayout android:layout_width="fill_parent" android:layout_height="40dp" android:background="@android:color/white" android:gravity="center_vertical" android:orientation="horizontal" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="20dp" android:text="SD卡存储信息:" /> <TextView android:id="@+id/tv3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="测试" /> </LinearLayout> <TextView android:layout_width="fill_parent" android:layout_height="1dp" android:background="#aeaea9" /> <LinearLayout android:layout_width="fill_parent" android:layout_height="40dp" android:background="@android:color/white" android:gravity="center_vertical" android:orientation="horizontal" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="20dp" android:text="手机分辨率:" /> <TextView android:id="@+id/tv4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="测试" /> </LinearLayout> <TextView android:layout_width="fill_parent" android:layout_height="1dp" android:background="#aeaea9" /> <LinearLayout android:layout_width="fill_parent" android:layout_height="40dp" android:background="@android:color/white" android:gravity="center_vertical" android:orientation="horizontal" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="20dp" android:text="网络是否连接:" /> <TextView android:id="@+id/tv5" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="测试" /> </LinearLayout> <TextView android:layout_width="fill_parent" android:layout_height="1dp" android:background="#aeaea9" /> <LinearLayout android:layout_width="fill_parent" android:layout_height="40dp" android:background="@android:color/white" android:gravity="center_vertical" android:orientation="horizontal" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="20dp" android:text="手机内存:" /> <TextView android:id="@+id/tv6" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="测试" /> </LinearLayout> <TextView android:layout_width="fill_parent" android:layout_height="1dp" android:background="#aeaea9" /> <LinearLayout android:layout_width="fill_parent" android:layout_height="40dp" android:background="@android:color/white" android:gravity="center_vertical" android:orientation="horizontal" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="20dp" android:text="手机CPU:" /> <TextView android:id="@+id/tv7" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="测试" /> </LinearLayout> <TextView android:layout_width="fill_parent" android:layout_height="1dp" android:background="#aeaea9" /> <LinearLayout android:layout_width="fill_parent" android:layout_height="40dp" android:background="@android:color/white" android:gravity="center_vertical" android:orientation="horizontal" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="20dp" android:text="手机IMEI:" /> <TextView android:id="@+id/tv8" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="测试" /> </LinearLayout> <TextView android:layout_width="fill_parent" android:layout_height="1dp" android:background="#aeaea9" /> </LinearLayout>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
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
MainActivity.java
package com.lgl.circle; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; import android.app.Activity; import android.app.ActivityManager; import android.app.ActivityManager.MemoryInfo; import android.content.Context; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.net.wifi.WifiInfo; import android.net.wifi.WifiManager; import android.os.Bundle; import android.os.Environment; import android.os.StatFs; import android.telephony.TelephonyManager; import android.text.format.Formatter; import android.util.DisplayMetrics; import android.util.Log; import android.view.View; import android.view.View.OnClickListener; import android.widget.TextView; import android.widget.Toast; import com.lgl.circle.R; public class AboutPhone extends Activity { private TextView tv1, tv2, tv3, tv4, tv5, tv6, tv7, tv8; private String[] cpuInfo = { "", "" }; // 1-cpu型号 //2-cpu频率 @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.about_phone); initView(); } private void initView() { tv1 = (TextView) findViewById(R.id.tv1); tv1.setText(getLocalIpAddress2()); tv2 = (TextView) findViewById(R.id.tv2); tv2.setText(getLocalMacAddress()); tv3 = (TextView) findViewById(R.id.tv3); // 需要判断手机上面SD卡是否插好,如果有SD卡的情况下,我们才可以访问得到并获取到它的相关信息,当然以下这个语句需要用if做判断 if (Environment.getExternalStorageState().equals( Environment.MEDIA_MOUNTED)) { // 取得sdcard文件路径 File path = Environment.getExternalStorageDirectory(); StatFs statfs = new StatFs(path.getPath()); // 获取block的SIZE long blocSize = statfs.getBlockSize(); // 获取BLOCK数量 long totalBlocks = statfs.getBlockCount(); // 空闲的Block的数量 long availaBlock = statfs.getAvailableBlocks(); // 计算总空间大小和空闲的空间大小 // 存储空间大小跟空闲的存储空间大小就被计算出来了。 long availableSize = blocSize * availaBlock; // (availableBlocks * blockSize)/1024 KIB 单位 // (availableBlocks * blockSize)/1024 /1024 MIB单位 long allSize = blocSize * totalBlocks; tv3.setText("可用:" + availableSize / 1024 / 1024 / 1024 + "GB" + " 总共:" + allSize / 1024 / 1024 / 1024 + "GB"); } else { tv3.setText("SD卡不可用"); } tv4 = (TextView) findViewById(R.id.tv4); DisplayMetrics displayMetrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); tv4.setText("分辨率:" + displayMetrics.widthPixels + "x" + displayMetrics.heightPixels); tv5 = (TextView) findViewById(R.id.tv5); ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo(); if (networkInfo == null || !networkInfo.isConnected()) { // info.setConnected(false); tv5.setText("当前无网络"); } else { // info.setConnected(true); tv5.setText("当前网络正常"); } tv6 = (TextView) findViewById(R.id.tv6); String availMemory = getAvailMemory(); String totalMemory = getTotalMemory(); tv6.setText("可用内存:" + availMemory + "\n" + "总内存:" + totalMemory); tv7 = (TextView) findViewById(R.id.tv7); getCpuInfo(); tv7.setText("cpu型号:" + cpuInfo[0] + "\n" + "cpu频率:" + cpuInfo[1]); tv8 = (TextView) findViewById(R.id.tv8); try { TelephonyManager mTelephonyMgr = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); String imei = mTelephonyMgr.getDeviceId(); tv8.setText("" + imei); } catch (Exception e) { // TODO: handle exception } findViewById(R.id.btn_back).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { finish(); } }); } // 获取手机ip method-2 public String getLocalIpAddress2() { // 获取wifi服务 WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE); // 判断wifi是否开启 if (!wifiManager.isWifiEnabled()) { wifiManager.setWifiEnabled(true); } WifiInfo wifiInfo = wifiManager.getConnectionInfo(); int ipAddress = wifiInfo.getIpAddress(); String ip = intToIp(ipAddress); return ip; } private String intToIp(int i) { return (i & 0xFF) + "." + ((i >> 8) & 0xFF) + "." + ((i >> 16) & 0xFF) + "." + (i >> 24 & 0xFF); } /** * mac地址 start */ public String getLocalMacAddress() { WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE); WifiInfo info = wifi.getConnectionInfo(); return info.getMacAddress(); } // 手机的内存信息主要在/proc/meminfo文件中,其中第一行是总内存,而剩余内存可通过ActivityManager.MemoryInfo得到。 private String getAvailMemory() {// 获取android当前可用内存大小 ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); MemoryInfo mi = new MemoryInfo(); am.getMemoryInfo(mi); // mi.availMem; 当前系统的可用内存 return Formatter.formatFileSize(getBaseContext(), mi.availMem);// 将获取的内存大小规格化 } private String getTotalMemory() { String str1 = "/proc/meminfo";// 系统内存信息文件 String str2; String[] arrayOfString; long initial_memory = 0; try { FileReader localFileReader = new FileReader(str1); BufferedReader localBufferedReader = new BufferedReader( localFileReader, 8192); str2 = localBufferedReader.readLine();// 读取meminfo第一行,系统总内存大小 arrayOfString = str2.split("\\s+"); for (String num : arrayOfString) { Log.i(str2, num + "\t"); } initial_memory = Integer.valueOf(arrayOfString[1]).intValue() * 1024;// 获得系统总内存,单位是KB,乘以1024转换为Byte localBufferedReader.close(); } catch (IOException e) { } return Formatter.formatFileSize(getBaseContext(), initial_memory);// Byte转换为KB或者MB,内存大小规格化 } /** * CPU */ private void getCpuInfo() { String str1 = "/proc/cpuinfo"; String str2 = ""; String[] arrayOfString; try { FileReader fr = new FileReader(str1); BufferedReader localBufferedReader = new BufferedReader(fr, 8192); str2 = localBufferedReader.readLine(); arrayOfString = str2.split("\\s+"); for (int i = 2; i < arrayOfString.length; i++) { cpuInfo[0] = cpuInfo[0] + arrayOfString[i] + " "; } str2 = localBufferedReader.readLine(); arrayOfString = str2.split("\\s+"); cpuInfo[1] += arrayOfString[2]; localBufferedReader.close(); } catch (IOException e) { } } }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
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
六.架包
1.Xutils
强大的xutils就不多说了
下载地址:http://download.csdn.net/detail/qq_26787115/9363335
2.Android animation
动画,注解
下载地址:http://download.csdn.net/detail/qq_26787115/9362755
3.Volley
Google官方网络框架
下载地址:http://download.csdn.net/detail/qq_26787115/9358787
七.工具
说到工具,其实辅助我们的工具还真不少,我以后慢慢的一个个添加
1.HJson
64位的 格式化json的PC端工具
下载地址:http://download.csdn.net/detail/qq_26787115/9365829
2.Xmind
思维导图制作软件,如果你的思路不清晰,可以用它来慢慢梳理
下载地址:http://www.xmind.net/cn/
3.MarkDown编辑器
这篇博文就是这个编辑器写出来的,真心很方便,大伙可以试试
下载地址:http://markdownpad.com/
十个编辑器推荐:http://www.csdn.net/article/2014-05-05/2819623
后续还会持续更新,如果由错误或者疑问欢迎评论留言!
相关文章推荐
- Android使用RecyclerView绘制表格
- Android 节操视频播放器jiecaovideoplayer使用
- Android 如何读取本地图片或者资源图片并自定义大小
- Android 抓包之Fiddler的使用
- Android课堂笔记——LinearLayout和RelativeLayout常用的两种布局方式
- Android 标题背景渐变
- android - TextView px和sp转换,以及getTextSize和setTextSize单位
- Android Studio的SVN Performing VCS Refresh/Commit 长时间不结束
- android打开系统相机分别获得原图和缩略图
- Android开发者选项-GPU显示配置文件无效
- android - RelativeLayout无法填充ScrollView
- android实现综合布局
- Android内核源码级调试环境搭建
- android底层驱动学习之调试驱动DEVICE_ATTR的原理及用法
- Android selector中的属性浅析
- Android service 简单介绍
- android 整理时间格式
- Android特效专辑(一)——水波纹过渡特效(首页)
- Android6.0启动-SystemServer
- 严格模式与内存泄漏,你必须知道的一切