小知识的积累,方便自己随时查看!
1. android透明度对应百分比数字
百分比 | 十六进制 |
---|---|
100% | FF |
99% | FC |
98% | FA |
97% | F7 |
96% | F5 |
95% | F2 |
94% | F0 |
93% | ED |
92% | EB |
91% | E8 |
90% | E6 |
89% | E3 |
88% | E0 |
87% | DE |
86% | DB |
85% | D9 |
84% | D6 |
83% | D4 |
82% | D1 |
81% | CF |
80% | CC |
79% | C9 |
78% | C7 |
77% | C4 |
76% | C2 |
75% | BF |
74% | BD |
73% | BA |
72% | B8 |
71% | B5 |
70% | B3 |
69% | B0 |
68% | AD |
67% | AB |
66% | A8 |
65% | A6 |
64% | A3 |
63% | A1 |
62% | 9E |
61% | 9C |
60% | 99 |
59% | 96 |
58% | 94 |
57% | 91 |
56% | 8F |
55% | 8C |
54% | 8A |
53% | 87 |
52% | 85 |
51% | 82 |
50% | 80 |
49% | 7D |
48% | 7A |
47% | 78 |
46% | 75 |
45% | 73 |
44% | 70 |
43% | 6E |
42% | 6B |
41% | 69 |
40% | 66 |
39% | 63 |
38% | 61 |
37% | 5E |
36% | 5C |
35% | 59 |
34% | 57 |
33% | 54 |
32% | 52 |
31% | 4F |
30% | 4D |
29% | 4A |
28% | 47 |
27% | 45 |
26% | 42 |
25% | 40 |
24% | 3D |
23% | 3B |
22% | 38 |
21% | 36 |
20% | 33 |
19% | 30 |
18% | 2E |
17% | 2B |
16% | 29 |
15% | 26 |
14% | 24 |
13% | 21 |
12% | 1F |
11% | 1C |
10% | 1A |
9% | 17 |
8% | 14 |
7% | 12 |
6% | 0F |
5% | 0D |
4% | 0A |
3% | 08 |
2% | 05 |
1% | 03 |
0% | 00 |
2. 代码设置shape背景
public static void createShare(View view, int radiusPx, int strokeWidth, int strokeColor) {
GradientDrawable drawable = new GradientDrawable();
drawable.setCornerRadius(radiusPx);
drawable.setStroke(strokeWidth, strokeColor);
if(Build.VERSION.SDK_INT < 16){
view.setBackgroundDrawable(drawable);
}else{
view.setBackground(drawable);
}
}
创建渐变色
int colors[] = { 0xff255779 , 0xff3e7492, 0xffa6c0cd };//分别为开始颜色,中间夜色,结束颜色
GradientDrawable gd = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, colors);
3. shape xml渐变色属性详解
1. android:angle="90"表示渐变的起始位置,这个值必须为45的倍数,包
括0,0表示从左往右渐变,逆时针旋转,依次是45,90,135.....,90表
示从下往上渐变,270表示从上往下渐变,剩下的大家依次去推理。
2. android:startColor="#9AFF9A",表示渐变的起始颜色
3. android:centerColor="#9ACD32"表示渐变的过渡颜色
4. android:endColor="#9AC0CD"表示渐变的结束颜色
5. type表示渐变的类型,有三种,分别是linear(线性变化),radial(辐
射渐变)以及sweep(扫描渐变)
当type为radial时,我们要设置android:gradientRadius="",这个表示渐变
的半径(线性渐变和扫描渐变不需要设置)
4. android 7.x 以上 PopupWindow 的showAsDropDown失效处理方案
a). 重写showAsDropDown方法:
@Override
public void showAsDropDown(View anchor) {
if(Build.VERSION.SDK_INT == 24) {
Rect rect = new Rect();
anchor.getGlobalVisibleRect(rect);
int h = anchor.getResources().getDisplayMetrics().heightPixels - rect.bottom;
setHeight(h);
}
super.showAsDropDown(anchor);
}
b). 使用showAtLocation方法:
if (Build.VERSION.SDK_INT >= 24) {
int[] point = new int[2];
v.getLocationInWindow(point);
mPopWindow.showAtLocation(((Activity) mContext).getWindow().getDecorView(), Gravity.NO_GRAVITY, 0, point[1] + v.getHeight());
} else {
mPopWindow.showAsDropDown(v);
}
5. Android 监听wifi状态-->注册广播(动态注册和静态注册)
class NetworkConnectChangedReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// 这个监听wifi的打开与关闭,与wifi的连接无关
if (WifiManager.WIFI_STATE_CHANGED_ACTION
.equals(intent.getAction())) {
int wifiState = intent
.getIntExtra(WifiManager.EXTRA_WIFI_STATE, 0);
EvtLog.e(TAG, "wifiState" + wifiState);
switch (wifiState) {
case WifiManager.WIFI_STATE_DISABLED:
break;
case WifiManager.WIFI_STATE_DISABLING:
break;
case WifiManager.WIFI_STATE_ENABLING:
break;
case WifiManager.WIFI_STATE_ENABLED:
break;
case WifiManager.WIFI_STATE_UNKNOWN:
break;
default:
break;
}
}
// 这个监听wifi的连接状态即是否连上了一个有效无线路由,当上边广播的状态是WifiManager
// .WIFI_STATE_DISABLING,和WIFI_STATE_DISABLED的时候,根本不会接到这个广播。
// 在上边广播接到广播是WifiManager.WIFI_STATE_ENABLED状态的同时也会接到这个广播,
// 当然刚打开wifi肯定还没有连接到有效的无线
if (WifiManager.NETWORK_STATE_CHANGED_ACTION
.equals(intent.getAction())) {
Parcelable parcelableExtra = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
if (null != parcelableExtra) {
NetworkInfo networkInfo = (NetworkInfo) parcelableExtra;
NetworkInfo.State state = networkInfo.getState();
boolean isConnected = state == NetworkInfo.State.CONNECTED;// 当然,这边可以更精确的确定状态
EvtLog.e(TAG, "isConnected" + isConnected);
if (isConnected) {
} else {
}
}
}
//这个监听网络连接的设置,包括wifi和移动数据的打开和关闭。.
//最好用的还是这个监听。wifi如果打开,关闭,以及连接上可用的连接都会接到监听。见log
//这个广播的最大弊端是比上边两个广播的反应要慢,如果只是要监听wifi,我觉得还是用上边两个配合比较合适
if (ConnectivityManager.CONNECTIVITY_ACTION.equals(intent.getAction())) {
ConnectivityManager manager = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
EvtLog.i(TAG, "CONNECTIVITY_ACTION");
assert manager != null;
NetworkInfo activeNetwork = manager.getActiveNetworkInfo();
if (activeNetwork != null) { // connected to the internet
if (activeNetwork.isConnected()) {
if (activeNetwork.getType() == ConnectivityManager.TYPE_WIFI) {
// connected to wifi
EvtLog.e(TAG, "当前WiFi连接可用 ");
} else if (activeNetwork.getType() == ConnectivityManager.TYPE_MOBILE) {
// connected to the mobile provider's data plan
EvtLog.e(TAG, "当前移动网络连接可用 ");
}
} else {
EvtLog.e(TAG, "当前没有网络连接,请确保你已经打开网络 ");
}
EvtLog.e(TAG, "info.getTypeName()" + activeNetwork.getTypeName());
EvtLog.e(TAG, "getSubtypeName()" + activeNetwork.getSubtypeName());
EvtLog.e(TAG, "getState()" + activeNetwork.getState());
EvtLog.e(TAG, "getDetailedState()"
+ activeNetwork.getDetailedState().name());
EvtLog.e(TAG, "getDetailedState()" + activeNetwork.getExtraInfo());
EvtLog.e(TAG, "getType()" + activeNetwork.getType());
} else { // not connected to the internet
EvtLog.e(TAG, "当前没有网络连接,请确保你已经打开网络 ");
}
}
}
}
6. 系统activity的打开方式:
-
调用系统分享
//分享文字 public void shareText(View view) { Intent shareIntent = new Intent(); shareIntent.setAction(Intent.ACTION_SEND); shareIntent.putExtra(Intent.EXTRA_TEXT, "This is my Share text."); shareIntent.setType("text/plain"); //设置分享列表的标题,并且每次都显示分享列表 startActivity(Intent.createChooser(shareIntent, "分享到")); } //分享单张图片 public void shareSingleImage(View view) { String imagePath = Environment.getExternalStorageDirectory() + File.separator + "test.jpg"; //由文件得到uri Uri imageUri = Uri.fromFile(new File(imagePath)); Log.d("share", "uri:" + imageUri); //输出:file:///storage/emulated/0/test.jpg Intent shareIntent = new Intent(); shareIntent.setAction(Intent.ACTION_SEND); shareIntent.putExtra(Intent.EXTRA_STREAM, imageUri); shareIntent.setType("image/*"); startActivity(Intent.createChooser(shareIntent, "分享到")); } //分享多张图片 public void shareMultipleImage(View view) { ArrayList
uriList = new ArrayList<>(); String path = Environment.getExternalStorageDirectory() + File.separator; uriList.add(Uri.fromFile(new File(path+"australia_1.jpg"))); uriList.add(Uri.fromFile(new File(path+"australia_2.jpg"))); uriList.add(Uri.fromFile(new File(path+"australia_3.jpg"))); Intent shareIntent = new Intent(); shareIntent.setAction(Intent.ACTION_SEND_MULTIPLE); shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uriList); shareIntent.setType("image/*"); startActivity(Intent.createChooser(shareIntent, "分享到")); } 系统相机以及系统相册选取功能
-
系统拨号页面的打开方式:
Intent intent =new Intent(); intent.setAction("android.intent.action.CALL_BUTTON"); startActivity(intent); Uri uri = Uri.parse("tel:xxxxxx"); Intent intent = new Intent(Intent.ACTION_DIAL, uri); startActivity(intent); -->到应用 Intent intent= new Intent("android.intent.action.DIAL"); intent.setClassName("com.android.contacts","com.android.contacts.DialtactsActivity");
-
系统通话记录
Intent intent=new Intent(); intent.setAction(Intent.ACTION_CALL_BUTTON); startActivity(intent);
-
联系人页面
Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); intent.setData(Contacts.People.CONTENT_URI); startActivity(intent); -->到应用 Intent intent= new Intent("com.android.contacts.action.LIST_STREQUENT"); intent.setClassName("com.android.contacts","com.android.contacts.DialtactsActivity");
-
调用联系人界面
Intent intent = new Intent(); intent.setAction(Intent.ACTION_PICK); intent.setData(Contacts.People.CONTENT_URI); startActivity(intent);
-
插入联系人界面
Intent intent=new Intent(Intent.ACTION_EDIT, Uri.parse("content://com.android.contacts/contacts/"+"1")); startActivity(intent);
-
到联系人列表页面
Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT); intent.setType("vnd.android.cursor.item/person"); intent.setType("vnd.android.cursor.item/contact"); intent.setType("vnd.android.cursor.item/raw_contact"); intent.putExtra(android.provider.ContactsContract.Intents.Insert.NAME, name); intent.putExtra(android.provider.ContactsContract.Intents.Insert.COMPANY,company); intent.putExtra(android.provider.ContactsContract.Intents.Insert.PHONE, tel); intent.putExtra(android.provider.ContactsContract.Intents.Insert.PHONE_TYPE, 3);
-
到短信界面
Intent intent = new Intent(Intent.ACTION_VIEW); intent.setType("vnd.android-dir/mms-sms"); //intent.setData(Uri.parse("content://mms-sms/conversations/"));//此为号码 startActivity(intent); -->到应用 Intent intent = new Intent("android.intent.action.CONVERSATION"); startActivity(intent);
7. 即使拉取手机错误日志:
adb bugreport ~/Destop