-
設(shè)置通知參數(shù)步驟: 第一步:創(chuàng)建Builder對(duì)象(是notification的builder)并new出Notification.Builder(this),通過(guò)調(diào)用builder的方法來(lái)設(shè)置,setSmallIcon(R.drawable...),setTicker...; 第二步(點(diǎn)擊后的響應(yīng)):創(chuàng)建PendingIntent對(duì)象并賦值為PendingIntent.getActivity(context,requestCode,intent,flags): context:this; requestCode:請(qǐng)求碼,0; intent:創(chuàng)建Intent對(duì)象,在new中根據(jù)需求選擇構(gòu)造的類.class; flags--0; 第三步:創(chuàng)建Notification對(duì)象,并將builder.build()賦值//4.1即以上,要用builder.build()方法,以下要用builder.getNotification()方法; 第四步:創(chuàng)建NotificationManager對(duì)象,因?yàn)槭窍到y(tǒng)的常用服務(wù),賦值為getSystemService(Context.NOTIFICATION_SERVICE),需強(qiáng)制轉(zhuǎn)化;調(diào)用成員函數(shù)notify(id,notification)來(lái)加載Notification,id是一個(gè)int值,表示notification的id,自行賦值即可;查看全部
-
//發(fā)送notification通知 NotificationManager manager; manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);// 取到通知控制類 Builder builder = new Notification.Builder(this); builder.setSmallIcon(R.drawable.XXX);//設(shè)置圖標(biāo) builder.setTicker("hello");//手機(jī)狀態(tài)欄的提示 builder.setWhen(System.currentTimeMills());//設(shè)置時(shí)間 builder.setContentTitle("通知欄通知");//設(shè)置標(biāo)題 builder.setContentText("我來(lái)自NotificationDemo");//設(shè)置通知內(nèi)容 Intent intent = new Intent(this,MainActivity.class); PendingIntent pintent = PendingIntent.getActivity(this,0,intent); builder.setContentIntent(pintent);//點(diǎn)擊后的意圖 //builder.setDefaults(Notification.DEFAULT_SOUND);//設(shè)置提示聲音 //builder.setDefaults(Notification.DEFAULT_LIGHTS);//設(shè)置指示燈 //builder.setDefaults(Notification.DEFAULT_VIBRATE);//設(shè)置震動(dòng) builder.setDefaults(Notification.DEFAULT_ALL);//三種效果都有 Notification not = builder.build();//4.1及以上 //builder.getNotification();//4.1以下 manager.notify(id, not);//顯示通知欄,id自定義 *注:指示燈和震動(dòng)需要設(shè)置android.permission.FLASHLIGHT和android.permission.VIBRATE權(quán)限查看全部
-
//自定義對(duì)話框 LayoutInflater inflater=LayoutInflater.from(this); View view=inflater.inflate(R.layout.dialog_layout, null); AlertDialog.Builder builder=new AlertDialog.Builder(this); builder.setTitle("自定義對(duì)話框"); builder.setIcon(R.drawable.ic_launcher); builder.setView(view); AlertDialog dialog=builder.create(); dialog.show();查看全部
-
/** * 顯示列表對(duì)話框 */ private void showDialog4() { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("部門(mén)列表");//設(shè)置標(biāo)題 builder.setIcon(R.drawable.ic_launcher);//設(shè)置圖標(biāo) builder.setItems(item_list, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub Toast.makeText(MainActivity.this, "我動(dòng)了"+item_list[which]+"!", Toast.LENGTH_SHORT).show(); } }); AlertDialog dialog = builder.create();//獲取dialog dialog.show();//顯示對(duì)話框 }查看全部
-
/** * 顯示多選按鈕對(duì)話框 */ private void showDialog3() { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("愛(ài)好");//設(shè)置標(biāo)題 builder.setIcon(R.drawable.ic_launcher);//設(shè)置圖標(biāo) builder.setMultiChoiceItems(multi_list, null, new DialogInterface.OnMultiChoiceClickListener() { @Override public void onClick(DialogInterface dialog, int which, boolean isChecked) { // TODO Auto-generated method stub if(isChecked){ Toast.makeText(MainActivity.this, "我喜歡上了"+multi_list[which]+"!", Toast.LENGTH_SHORT).show(); }else{ Toast.makeText(MainActivity.this, "我不喜歡"+multi_list[which]+"了!", Toast.LENGTH_SHORT).show(); } } }); builder.setNegativeButton("取消", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub dialog.dismiss();//隱藏對(duì)話框 } }); AlertDialog dialog = builder.create();//獲取dialog dialog.show();//顯示對(duì)話框 }查看全部
-
//單選對(duì)話框 String[] single_list={"男","女"}; private void showDialog2(){ AlertDialog.Builder=new AlertDialog.Builder(this); Builder.setTitle("選擇性別");//設(shè)置標(biāo)題 Builder.setIcon(R.drawable.ic_launcher);//設(shè)置圖標(biāo) //設(shè)置選項(xiàng):第二個(gè)參數(shù)0表示默認(rèn)選中第一個(gè)選項(xiàng) Builder.setSingleChoiceItems(single_list,0,new DialogInterface.OnClickListener(){ public void onClick(DialogInterface dialog,int which){ String str=single_list[which]; Toast.makeText(MainActivity.this,"這個(gè)人的性別為"+str,Toast.LENGTH_SHORT).show(); } }); AlertDialog dialog=builder.create(); dialog.show(); }查看全部
-
AlertDialog常用方法查看全部
-
完全自定義Toast: 新建一個(gè)Toast樣式的layout布局toast_layout.xml //獲得inflater LayoutInflater inflater = LayoutInflater.from(this); // 通過(guò)inflater來(lái)將我們自定義的toast的布局轉(zhuǎn)化為view的控件 View view = inflater.inflate(R.layout.toast_layout, null); //初始化toast Toast toast=new Toast (this); // 通過(guò)toast.setView的方法將我們上面得到的view添加到toast中去 toast.setView(view); //顯示toast toast.show();查看全部
-
1.基本Toast 2.自定Toast toast.setGravity(Gravity.CENTER,0,0); 設(shè)置Toast的位置(相對(duì)于布局居中 后面參數(shù)分別為相對(duì)于前面參數(shù)的X Y軸的偏移量) 3.帶有圖片的Toast LinearLayout linear = (LinearLayout) toast.getView(); ImageView img = new ImageView(this); img.setImageResource(圖片id); linear.addView(img,0); (第二個(gè)參數(shù)設(shè)置圖片在文字的上方位置) toast.show();查看全部
-
什么是Toast 1.Toast是一種提供給用戶簡(jiǎn)潔提示信息的視圖 2.該視圖以浮與應(yīng)用程序智商的形式呈現(xiàn)給用戶.Toast提示界面不獲取焦點(diǎn),所以不影響用戶的操作.Toast提示就是在不影響用戶使用程序的同時(shí),給予用戶提供某些提示信息.有兩個(gè)例子就是音量控制盒設(shè)置信息保存成功 3.Android提供的Toast類可以創(chuàng)建和顯示該Toast信息. Toast常用方法 Toast.makeText(context,text,duration); //返回值為T(mén)oast //context:上下文 //text:提示的內(nèi)容 //duration:持續(xù)的時(shí)間 toast.setDuration(duration);//設(shè)置持續(xù)時(shí)間 toast.setGravity(gravity,x0ffset,y0ffset);//設(shè)置toast位置 toast.setText(s);//設(shè)置提示內(nèi)容 toast.show();//顯示查看全部
-
設(shè)置通知參數(shù)步驟: 第一步:創(chuàng)建Builder對(duì)象(是notification的builder)并new出Notification.Builder(this),通過(guò)調(diào)用builder的方法來(lái)設(shè)置,setSmallIcon(R.drawable...),setTicker...; 第二步(點(diǎn)擊后的響應(yīng)):創(chuàng)建PendingIntent對(duì)象并賦值為PendingIntent.getActivity(context,requestCode,intent,flags): context:this; requestCode:請(qǐng)求碼,0; intent:創(chuàng)建Intent對(duì)象,在new中根據(jù)需求選擇構(gòu)造的類.class; flags--0; 第三步:創(chuàng)建Notification對(duì)象,并將builder.build()賦值//4.1即以上,要用builder.build()方法,以下要用builder.getNotification()方法; 第四步:創(chuàng)建NotificationManager對(duì)象,因?yàn)槭窍到y(tǒng)的常用服務(wù),賦值為getSystemService(Context.NOTIFICATION_SERVICE),需強(qiáng)制轉(zhuǎn)化;調(diào)用成員函數(shù)notify(id,notification)來(lái)加載Notification,id是一個(gè)int值,表示notification的id,自行賦值即可;查看全部
-
重寫(xiě)oncreateoptionsmenu 有兩種方法獲取內(nèi)容: xml 和menu.add(groupid,itemid,order,title) 設(shè)置監(jiān)聽(tīng)器onoptionsitemselected 可以用switch case為itemid查看全部
-
用日志的辦法判斷空指針位置查看全部
-
LogCat窗口左側(cè)是日志過(guò)濾器 All messages是所有日志只要是和程序有關(guān)的都會(huì)記錄 上方綠色小加號(hào)是添加過(guò)濾器: Filter Name過(guò)濾器名稱,可以隨意起 by Log Tag通過(guò)標(biāo)簽名過(guò)濾 by Log Message通過(guò)日志信息過(guò)濾 by PID通過(guò)進(jìn)程ID過(guò)濾 by Application Name通過(guò)應(yīng)用程序名過(guò)濾 by Log Level通過(guò)日志等級(jí)過(guò)濾 常用的是Tag和AnimationName 上方減號(hào)按鈕是刪除選中的過(guò)濾器 上方書(shū)寫(xiě)的按鈕是編輯選中的過(guò)濾器查看全部
-
LogCat的作用 1.LogCat是用來(lái)獲取系統(tǒng)日志信息的工具,可以等到的信息包括Dalvik虛擬機(jī)信息,進(jìn)程信息,Android運(yùn)行時(shí)信息,以及應(yīng)用程序信息 2.我們可以通過(guò)添加程序日志的方式,來(lái)對(duì)程序進(jìn)行簡(jiǎn)單的追蹤,LogCat是比較輕便簡(jiǎn)介的調(diào)試模式 3.與Debug調(diào)試的區(qū)別: Debug調(diào)試一般用于相對(duì)來(lái)說(shuō)比較復(fù)雜的問(wèn)題 LogCat一般用于相對(duì)來(lái)說(shuō)比較容易追蹤的問(wèn)題 如果eclipse沒(méi)有自動(dòng)啟動(dòng)LogCat窗口,可以通過(guò) Window-->Show View-->Other-->Android-->LogCat-->ok LogCat窗口右側(cè) Level是日志的級(jí)別 Tame日志輸出時(shí)間 PID進(jìn)程ID TID線程ID Application應(yīng)用程序 Tag標(biāo)簽 Text輸出的日志信息 Log日志級(jí)別 1.Log.v(tag,message);//verbose模式,打印最詳細(xì)的日志,顏色為黑色 2.Log.d(tag,message);//debug級(jí)別的日志,顏色為藍(lán)色 3.Log.i(tag,message);//info級(jí)別的日志,顏色為綠色 4.Log.w(tag,message);//warn級(jí)別的日志,顏色為橙色 5.Log.v(tag,message);//error級(jí)別的日志,顏色為紅色 tag用來(lái)標(biāo)記Log消息的源頭,而message則是這條Log的內(nèi)容。 錯(cuò)誤信息的級(jí)別最高,其次是警告信息,然后是通知信息以及Debug信息,級(jí)別最低的是詳細(xì)信息。 從日志的輸出數(shù)量來(lái)算,error,warn,info,debug,verbose,數(shù)量從少到多查看全部
舉報(bào)
0/150
提交
取消