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