Android高效率编码-细节,控件,架包,功能,工具,开源汇总
版权声明:本文为博主原创文章,博客地址:http://blog.csdn.net/qq_26787115,未经博主允许不得转载。
其实写博客的初衷也并不是说什么分享技术,毕竟咱还只是个小程序员,最大的目的就是对自我的知识积累,以后万一编码的时候断片了,也可以翻出来看看,这样子对自己也有好处,所以今天就汇总一下一些需要的东西。多图来了,加油!
一.游戏
小熊打字,我刚接触电脑练习打字的时候用到的
下载地址:http://download.csdn.net/detail/qq_26787115/9365721
二.色彩
这张颜色表上的颜色都太赞了
三.控件
1.TextView
android:singleLine=
"true"
12
12
<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"
/>
12345678910
12345678910
文本添加下划线
2.EditText
android:
numeric=
"integer"
android:phoneNumber=
"true"
android:password=
"true"
123456
123456
3.LinearLayout
各种属性
4.RelativeLayout
各种属性
扁平的按钮xml写法
6.WebView
加载网页
7.RatiBar评分条
评分
8.ListView
基本写法
ArrayAdapter写法 SimpleAdapter写法
ToggleButton更换主题
10.Spinner
布局
代码
11.Dialog
属性
用法
12.AutoCompleteTextView
AutoCompleteTextView
MultiAutoCompleteTextView
13.TabHost
布局
Activity TabHostActivity自定义Title字体颜色等
菜单
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();
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>
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
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 = {
"",
"" };
@Override
protected void onCreate(Bundle savedInstanceState) {
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);
if (Environment.getExternalStorageState().equals(
Environment.MEDIA_MOUNTED)) {
File path = Environment.getExternalStorageDirectory();
StatFs statfs =
new StatFs(path.getPath());
long blocSize = statfs.getBlockSize();
long totalBlocks = statfs.getBlockCount();
long availaBlock = statfs.getAvailableBlocks();
long availableSize = blocSize * availaBlock;
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()) {
tv5.setText(
"当前无网络");
}
else {
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) {
}
findViewById(R.id.btn_back).setOnClickListener(
new OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
}
public String
getLocalIpAddress2() {
WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
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();
}
private String
getAvailMemory() {
ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
MemoryInfo mi =
new MemoryInfo();
am.getMemoryInfo(mi);
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();
arrayOfString = str2.split(
"\\s+");
for (String num : arrayOfString) {
Log.i(str2, num +
"\t");
}
initial_memory = Integer.valueOf(arrayOfString[
1]).intValue() *
1024;
localBufferedReader.close();
}
catch (IOException e) {
}
return Formatter.formatFileSize(getBaseContext(), initial_memory);
}
/**
* 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) {
}
}
}
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
六.架包
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
后续还会持续更新,如果由错误或者疑问欢迎评论留言!