Android Learning notes, call system Gallery, add custom fonts, screenshots

Source: Internet
Author: User

The first day of the new year began to learn the MU class Spring Festival activities in the Android wish to share a lesson, learned a few knowledge points, in this record.

1. Call System Gallery
Call the system library with intent, the procedure is to pop up the system library selector, select the picture to get to the selected picture. The code is as follows:

//call where it's neededIntent Intent =NewIntent (Intent.action_pick,NULL); Intent.setdataandtype (MediaStore.Images.Media.EXTERNAL_CONTENT_URI,"Image/*"); Startactivityforresult (Intent,100);//100 for Requestcode//get results in Onactivityresult@Overrideprotected voidOnactivityresult (intRequestcode,intResultCode, Intent data) {    Super. Onactivityresult (Requestcode, ResultCode, data); if(ResultCode = = Result_ok && Requestcode = = 100) {        if(Data! =NULL) {Mphoto.setimageuri (Data.getdata ());//Mphoto is a imageview        }    }}

Here is the URI of the picture in the Onactivityresult.

2. Add a custom font
To add a custom self-assembly in two steps:
A: Is adding font files to the Project asserts folder (cannot be added to res because resources in RES are compressed when packaged, font files cannot be compressed),
B: Set the font by code

// Mword is a edittext, of course, can also be used with TextView, font files exist in the project's Asserts/fonts folder Mword.settypeface (Typeface.createfromasset ( Getassets (), "Fonts/test.ttf"));

3. Screen
Code:

/**@return*/private  Bitmap getscreenshot ()    {= GetWindow (). Getdecorview ();    View.setdrawingcacheenabled (true);    View.builddrawingcache ();     return View.getdrawingcache ();}

Occasionally encounter the view of the Getdrawingcache is empty then you can use the following methods to solve:

 public  static  Bitmap Loadbitmapfromview (View V, boolean   Isparemt) { /span>if  (v = = null   return  null  ;      } Bitmap screenshot; Screenshot  = Bitmap.createbitmap (V.getwidth (), V.getheight (),      hdconstantset.bitmap_quality);      Canvas c  = new   Canvas (screenshot);      C.translate (-v.getscrollx (),-v.getscrolly ());      V.draw (c);   return   screenshot; }

Reference article:http://blog.csdn.net/huangbiao86/article/details/9053429

Android Learning notes, call system Gallery, add custom fonts, screen

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.