android 特殊用法一

1.讓一個圖片透明:

1.             Bitmap buffer = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_4444);buffer.eraseColor(Color.TRANSPARENT);  

2.直接發送郵件:

1.             Intent intent = new Intent(Intent.ACTION_SENDTO,  Uri .fromParts("mailto", "test@test.com", null));    

2.             intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);    

3.             context.startActivity(intent);  

3.程序控制屏幕變亮:

1.             WindowManager.LayoutParams lp = getWindow().getAttributes();    

2.             lp.screenBrightness = 100 / 100.0f;    

3.             getWindow().setAttributes(lp); 

4.過濾特定文本

1.             Filter filter = myAdapter.getFilter();    

2.             filter.filter(mySearchText);  

5.scrollView scroll停止事件

1.             setOnScrollListener(new OnScrollListener(){       

2.             public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {         

3.             // TODO Auto-generated method stub    }       

4.             public void onScrollStateChanged(AbsListView view, int scrollState) {         

5.             // TODO Auto-generated method stub         

6.             if(scrollState == 0) Log.i("a", "scrolling stopped…");    }  });}  

6. 對於特定的程序 發起一個關聯供打開

1.             Bitmap bmp = getImageBitmap(jpg);    

2.             String path = getFilesDir().getAbsolutePath() + "/test.png";    

3.             File file = new File(path);    

4.             FileOutputStream fos = new FileOutputStream(file);    

5.             bmp.compress( CompressFormat.PNG, 100, fos );    

6.               fos.close();    

7.                  

8.                Intent intent = new Intent();    

9.                intent.setAction(android .content.Intent.ACTION_VIEW);    

10.            intent.setDataAndType(Uri .fromFile(new File(path)), "image/png");    

11.            startActivity(intent);    

12.         對於圖片上邊的不適用索引格式會出錯。    

13.         Intent intent = new Intent();     

14.         intent.setAction(android .content.Intent.ACTION_VIEW);     

15.         File file = new File("/sdcard/test.mp4");     

16.         intent.setDataAndType(Uri .fromFile(file), "video/*");     

17.         startActivity(intent);    

18.           

19.         Intent intent = new Intent();     

20.         intent.setAction(android .content.Intent.ACTION_VIEW);     

21.         File file = new File("/sdcard/test.mp3");     

22.         intent.setDataAndType(Uri .fromFile(file), "audio/*");     

23.         startActivity(intent);  

7.設置文本外觀

1.             setTextAppearance(context, android .R.style.TextAppearance_Medium);    

2.             android :textAppearance="?android :attr/textAppearanceMedium" 

8.設置單獨的發起模式:

1.             <activity           

2.               android :name=".ArtistActivity"           

3.               android :label="Artist"           

4.               android :launchMode="singleTop">       

5.               </activity>    

6.               www.aiwalls.com

7.             Intent i = new Intent();           

8.                i.putExtra(EXTRA_KEY_ARTIST, id);          

9.                 i.setClass(this, ArtistActivity.class);           

10.             i.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);          

11.              startActivity(i);  

 

摘自 LuoXianXiong,您的夥伴

發佈留言