android 特殊用法一

來源:互聯網
上載者:User

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.2cto.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,您的夥伴

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.