小知識(shí)的積累胰坟,方便自己隨時(shí)查看笔横!
1. android透明度對(duì)應(yīng)百分比數(shù)字
百分比 | 十六進(jìn)制 |
---|---|
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. 代碼設(shè)置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);
}
}
創(chuàng)建漸變色
int colors[] = { 0xff255779 , 0xff3e7492, 0xffa6c0cd };//分別為開(kāi)始顏色,中間夜色喂急,結(jié)束顏色
GradientDrawable gd = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, colors);
3. shape xml漸變色屬性詳解
<gradient
android:angle="90"
android:centerColor="#9ACD32"
android:endColor="#9AC0CD"
android:startColor="#9AFF9A"
android:type="linear"
android:useLevel="false" />
1. android:angle="90"表示漸變的起始位置讥蔽,這個(gè)值必須為45的倍數(shù)冶伞,包
括0响禽,0表示從左往右漸變荚醒,逆時(shí)針旋轉(zhuǎn)界阁,依次是45泡躯,90,135.....技健,90表
示從下往上漸變雌贱,270表示從上往下漸變欣孤,剩下的大家依次去推理导街。
2. android:startColor="#9AFF9A"搬瑰,表示漸變的起始顏色
3. android:centerColor="#9ACD32"表示漸變的過(guò)渡顏色
4. android:endColor="#9AC0CD"表示漸變的結(jié)束顏色
5. type表示漸變的類(lèi)型泽论,有三種翼悴,分別是linear(線性變化),radial(輻
射漸變)以及sweep(掃描漸變)
當(dāng)type為radial時(shí)鹦赎,我們要設(shè)置android:gradientRadius=""古话,這個(gè)表示漸變
的半徑(線性漸變和掃描漸變不需要設(shè)置)
4. android 7.x 以上 PopupWindow 的showAsDropDown失效處理方案
a). 重寫(xiě)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 監(jiān)聽(tīng)wifi狀態(tài)-->注冊(cè)廣播(動(dòng)態(tài)注冊(cè)和靜態(tài)注冊(cè))
class NetworkConnectChangedReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// 這個(gè)監(jiān)聽(tīng)wifi的打開(kāi)與關(guān)閉陪踩,與wifi的連接無(wú)關(guān)
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;
}
}
// 這個(gè)監(jiān)聽(tīng)wifi的連接狀態(tài)即是否連上了一個(gè)有效無(wú)線路由,當(dāng)上邊廣播的狀態(tài)是WifiManager
// .WIFI_STATE_DISABLING姥饰,和WIFI_STATE_DISABLED的時(shí)候列粪,根本不會(huì)接到這個(gè)廣播荆秦。
// 在上邊廣播接到廣播是WifiManager.WIFI_STATE_ENABLED狀態(tài)的同時(shí)也會(huì)接到這個(gè)廣播,
// 當(dāng)然剛打開(kāi)wifi肯定還沒(méi)有連接到有效的無(wú)線
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;// 當(dāng)然吃媒,這邊可以更精確的確定狀態(tài)
EvtLog.e(TAG, "isConnected" + isConnected);
if (isConnected) {
} else {
}
}
}
//這個(gè)監(jiān)聽(tīng)網(wǎng)絡(luò)連接的設(shè)置赘那,包括wifi和移動(dòng)數(shù)據(jù)的打開(kāi)和關(guān)閉募舟。.
//最好用的還是這個(gè)監(jiān)聽(tīng)闻察。wifi如果打開(kāi)辕漂,關(guān)閉钉嘹,以及連接上可用的連接都會(huì)接到監(jiān)聽(tīng)。見(jiàn)log
//這個(gè)廣播的最大弊端是比上邊兩個(gè)廣播的反應(yīng)要慢缨睡,如果只是要監(jiān)聽(tīng)wifi奖年,我覺(jué)得還是用上邊兩個(gè)配合比較合適
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, "當(dāng)前WiFi連接可用 ");
} else if (activeNetwork.getType() == ConnectivityManager.TYPE_MOBILE) {
// connected to the mobile provider's data plan
EvtLog.e(TAG, "當(dāng)前移動(dòng)網(wǎng)絡(luò)連接可用 ");
}
} else {
EvtLog.e(TAG, "當(dāng)前沒(méi)有網(wǎng)絡(luò)連接,請(qǐng)確保你已經(jīng)打開(kāi)網(wǎng)絡(luò) ");
}
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, "當(dāng)前沒(méi)有網(wǎng)絡(luò)連接嗅义,請(qǐng)確保你已經(jīng)打開(kāi)網(wǎng)絡(luò) ");
}
}
}
}
6. 系統(tǒng)activity的打開(kāi)方式:
-
調(diào)用系統(tǒng)分享
//分享文字 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"); //設(shè)置分享列表的標(biāo)題之碗,并且每次都顯示分享列表 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<Uri> 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, "分享到")); }
系統(tǒng)相機(jī)以及系統(tǒng)相冊(cè)選取功能
-
系統(tǒng)撥號(hào)頁(yè)面的打開(kāi)方式:
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); -->到應(yīng)用 Intent intent= new Intent("android.intent.action.DIAL"); intent.setClassName("com.android.contacts","com.android.contacts.DialtactsActivity");
-
系統(tǒng)通話記錄
Intent intent=new Intent(); intent.setAction(Intent.ACTION_CALL_BUTTON); startActivity(intent);
-
聯(lián)系人頁(yè)面
Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); intent.setData(Contacts.People.CONTENT_URI); startActivity(intent); -->到應(yīng)用 Intent intent= new Intent("com.android.contacts.action.LIST_STREQUENT"); intent.setClassName("com.android.contacts","com.android.contacts.DialtactsActivity");
-
調(diào)用聯(lián)系人界面
Intent intent = new Intent(); intent.setAction(Intent.ACTION_PICK); intent.setData(Contacts.People.CONTENT_URI); startActivity(intent);
-
插入聯(lián)系人界面
Intent intent=new Intent(Intent.ACTION_EDIT, Uri.parse("content://com.android.contacts/contacts/"+"1")); startActivity(intent);
-
到聯(lián)系人列表頁(yè)面
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/"));//此為號(hào)碼 startActivity(intent); -->到應(yīng)用 Intent intent = new Intent("android.intent.action.CONVERSATION"); startActivity(intent);
7. 即使拉取手機(jī)錯(cuò)誤日志:
adb bugreport ~/Destop