Basic common knowledge of Android (continuous Update)
Last Update:2015-06-20
Source: Internet
Author: User
<span id="Label3"></p><strong><strong>//can Get information on the screen</strong></strong><p><p>Displaymetrics dm = new Displaymetrics ();</p></p>Getwindowmanager (). getdefaultdisplay (). getmetrics (dm);<p><p>dm.widthpixels; Get wide pixels<br>dm.heightpixels; Get High pixel</p></p><p><p></p></p><p><p><strong>Get a local calendar</strong></p></p>Calendar c=calendar.getinstance (); Myear=c.get (calendar.year);//get the year mmonth=c.get (calendar.month);//get month Mday=c.get (calendar.day_of_month);//get a numbered Mhour=c.get (calendar.hour_of_day);//get Hours<p><p>Mminute=c.get (calendar.minute); Get minutes</p></p><p><p></p></p><p><p><strong>Make edittext content visible or hidden</strong></p></p><p><p><span style="text-align: left; font-size: 10pt; font-family: ‘Courier New‘; color: #3f7f5f;">/* <span style="text-align: left; font-size: 10pt; font-family: 宋体;">Set <span style="text-align: left; font-size: 10pt; font-family: ‘Courier New‘; color: #3f7f5f;">the contents of the EditText <span style="text-align: left; font-size: 10pt; font-family: 宋体;">as visible <span style="text-align: left; font-size: 10pt; font-family: ‘Courier New‘; color: #3f7f5f;">*</span> </span> </span> </span> /</span></p></p><p style="text-align: left; text-autospace: none;" align="left"><p style="text-align: left; text-autospace: none;" align="left"><span style="font-size: 10pt; font-family: ‘Courier New‘;"><span style="font-size: 10.0pt; font-family: ‘Courier New‘; color: #0000c0;">editText<span style="font-size: 10pt; font-family: ‘Courier New‘;">. Settransformationmethod (</span> </span></span></p></p><p><p><span style="font-size: 10pt; font-family: ‘Courier New‘;">Hidereturnstransformationmethod. <em>getinstance</em> ());</span></p></p><p><p></p></p><p style="text-align: left; text-autospace: none;" align="left"><p style="text-align: left; text-autospace: none;" align="left"><span style="font-size: 10.0pt; font-family: ‘Courier New‘; color: #3f7f5f;">/* <span style="font-size: 10.0pt; font-family: 宋体; courier new"4courier new";courier new"; color: #3F7F5F;">Set <span style="font-size: 10.0pt; font-family: ‘Courier New‘; color: #3f7f5f;">the contents of the EditText <span style="font-size: 10.0pt; font-family: 宋体; courier new"4courier new";courier new"; color: #3F7F5F;">as hidden <span style="font-size: 10.0pt; font-family: ‘Courier New‘; color: #3f7f5f;">*</span> </span> </span> </span> /</span></p></p><p style="text-align: left; text-autospace: none;" align="left"><p style="text-align: left; text-autospace: none;" align="left"><span style="font-size: 10pt; font-family: ‘Courier New‘;"><span style="font-size: 10.0pt; font-family: ‘Courier New‘; color: #0000c0;">editText<span style="font-size: 10pt; font-family: ‘Courier New‘;">. Settransformationmethod (</span> </span></span></p></p> <span style="font-family: ‘Courier New‘; font-size: 10pt;"><span style="font-family: ‘Courier New‘; font-size: 10pt;"><span style="font-family: ‘Courier New‘; font-size: 10pt;">Passwordtransformationmethod. <em style="font-family: ‘Courier New‘; font-size: 10pt;">getinstance</em> <span style="font-family: ‘Courier New‘; font-size: 10pt;">()); </span></span></span></span><p><p></p></p><strong><strong>//do not automatically eject the soft keyboard when activating activity</strong></strong><p><p>GetWindow (). Setsoftinputmode (WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);</p></p><p><p></p></p><strong><strong>//set full Screen (set before Setcontentview)</strong></strong>GetWindow (). setflags (WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);<p><p><br><strong>Set Cancel fullscreen</strong></p></p><p><p>Windowmanager.layoutparams attrs = GetWindow (). getattributes ();</p></p><p><p>Attrs.flags &= (~windowmanager.layoutparams.flag_fullscreen); GetWindow (). setattributes (attrs); GetWindow (). clearflags (WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);</p></p><p><p></p></p><strong><strong>//set Untitled</strong></strong><strong><strong>(set before Setcontentview)</strong></strong><p><p>Requestwindowfeature (window.feature_no_title);</p></p><p><p></p></p><p><p><strong>//set prohibit mobile phone horizontal screen</strong> <strong>(set before Setcontentview)</strong></p></p><p><p>Setrequestedorientation (activityinfo.screen_orientation_nosensor);</p></p><p><p></p></p><p><p><strong>Call the Phone's default camera function, and can set the storage location</strong></p></p><p><p>Intent i = new Intent ("android.media.action.IMAGE_CAPTURE");</p></p><p><p>I.putextra (mediastore.extra_output, uri.fromfile (new File (environment. getexternalstoragedirectory (), "pic.jpg"))) ;</p></p><p><p></p></p><p><p><strong>Solve the Chinese garbled method</strong></p></p><p><p>A. use GetBytes ("") to re-encode the kanji to get its byte array</p></p><p><p>B. then use new String (bytes[], "decode Mode") to decode the byte array accordingly</p></p><p><p></p></p><p><p><strong>Easy layout of the screen in Android</strong></p></p><p><p>The layout of the vertical screen is usually set under layout, and the layout of the horizontal screen creates a folder of name Layout-land in the same level folder of Layout. The simulator can be quickly switched using the ctrl+f11.</p></p><p><p></p></p><p><p><strong>Android screen toggle does not restart activity</strong></p></p><p><p><span style="font-family: 宋体, Arial; line-height: 18px; text-align: left; text-indent: 28px; font-size: 12pt;">The Activit element in Androidmanifest.xml adds this property to <span style="font-size: 12pt;">Android</span><span style="font-family: 宋体, Arial; line-height: 18px; text-align: left; text-indent: 28px; font-size: 12pt;">: configchanges= "orientation|keyboardhidden"</span></span></p></p><p><p>The following methods are then overloaded in activity:</p></p><span class="cnblogs_code_copy"><span class="cnblogs_code_copy"></span></span><span style="font-family: verdana, ‘courier new‘; font-size: 14px; line-height: 21px; color: #0000ff;"><span style="font-family: verdana, ‘courier new‘; font-size: 14px; line-height: 21px; color: #0000ff;">public <span style="font-family: verdana, ‘courier new‘; font-size: 14px; line-height: 21px; color: #0000ff;">void<span style="font-family: verdana, ‘courier new‘; font-size: 14px; line-height: 21px;"> onconfigurationchanged (Configuration newconfig) {</span> </span> </span></span><p><span style="color: #008000;">//<span style="color: #008000;">TODO auto-generated Method Stub<br><span style="color: #0000ff;"><span style="color: #0000ff;"> if (newconfig.orientation==configuration.orientation_landscape) {<br> setcontentview ( r.layout.imageswitch); <br> <span style="color: #008000;">//< Span style= "color: #008000;" > horizontal screen <span style="color: #008000;"> <br> } <span style="color: #0000ff; ">else {<br> setcontentview ( r.layout.editcontact); <span style="color: #008000;">//<span style="color: #008000;"> vertical <span style="color: #008000;"> <br> } <br> <span style=" Color: #0000ff; ">super.onconfigurationchanged (newconfig); </span> </span> </span> </span> </span> </span> </span> </span> </span></span></span></p><p><p><span style="font-family: verdana, ‘courier new‘; font-size: 14px; line-height: 21px;">}</span></p></p><span class="cnblogs_code_copy"><span class="cnblogs_code_copy"></span></span><p><p><br>Uninstall the Program:<br><br><span style="line-height: 1.5;">Uri Packageuri = Uri.parse ("package:com.demo.CanavaCancel");</span></p></p>Intent uninstallintent = new Intent (intent.action_delete, packageuri); StartActivity (uninstallintent);<p><p><br>Install Apk:</p></p>String str = "/canavacancel.apk"; String FileName = environment.getexternalstoragedirectory () + str; Intent Intent = new Intent (intent.action_view); Intent.setdataandtype (uri.fromfile (new File), "application/vnd.android.package-archive");<p><p>StartActivity (intent)</p></p><p><p>Basic common knowledge of Android (continuous Update)</p></p></span>