Objective
Every time sharing means progress every time, this series to be practical, welcome and I share and recommend useful code Snippets ~ ~
StatementWelcome reprint, but please keep the original source of the article:)Blog Park: http://www.cnblogs.comFarmer Uncle: Http://over140.cnblogs.com
Body
1. Expand and close the status bar
PublicStaticFinalvoidCollapsestatusbar (Context ctx) {
Object Sbservice = Ctx.getsystemservice ("StatusBar");
Try{
class<?> Statusbarmanager = Class.forName ("Android.app.StatusBarManager");
Method collapse;
if(Build.VERSION.SDK_INT >= build.version_codes. JELLY_BEAN_MR1) {
Collapse = Statusbarmanager.getmethod ("Collapsepanels");
}Else{
Collapse = Statusbarmanager.getmethod ("collapse");
}
Collapse.invoke (Sbservice);
}Catch(Exception e) {
E.printstacktrace ();
}
}
PublicStaticFinalvoidExpandstatusbar (Context ctx) {
Object Sbservice = Ctx.getsystemservice ("StatusBar");
Try{
class<?> Statusbarmanager = Class.forName ("Android.app.StatusBarManager");
Method expand;
if(Build.VERSION.SDK_INT >= 17) {
expand = Statusbarmanager.getmethod ("Expandnotificationspanel");
}Else{
expand = Statusbarmanager.getmethod ("expand");
}
Expand.invoke (Sbservice);
}Catch(Exception e) {
E.printstacktrace ();
}
}
Purpose: Can be used to close the status bar after clicking Notifacation
2. Get Status bar height
PublicStaticintGetstatusbarheight (Context context) {
class<?> C =NULL;
Object obj =NULL;
Field field =NULL;
intx = 0, statusbarheight = 0;
Try{
c = Class.forName ("Com.android.internal.r$dimen");
obj = C.newinstance ();
field = C.getfield ("Status_bar_height");
x = Integer.parseint (Field.get (obj). toString ());
Statusbarheight = Context.getresources (). getdimensionpixelsize (x);
}Catch(Exception E1) {
E1.printstacktrace ();
}
returnStatusbarheight;
}
3, the ListView uses the Viewholder extremely shorthand method
PublicStatic<textendsView> T Getadapterview (View Convertview,intID) {
Sparsearray<view> Viewholder = (sparsearray<view>) convertview.gettag ();
if(Viewholder = =NULL) {
Viewholder =NewSparsearray<view> ();
Convertview.settag (Viewholder);
}
View Childview = viewholder.get (ID);
if(Childview = =NULL) {
Childview = Convertview.findviewbyid (ID);
Viewholder.put (ID, Childview);
}
return(T) Childview;
}
Usage:
@Override
PublicView GetView (intPosition, View Convertview, ViewGroup parent) {
if(Convertview = =NULL) {
Convertview = Layoutinflater.from (Getactivity ()). Inflate (R.layout.fragment_feed_item, parent,false);
}
ImageView Thumnailview = Getadapterview (Convertview, R.id.video_thumbnail);
ImageView Avatarview = Getadapterview (Convertview, R.id.user_avatar);
ImageView Appiconview = Getadapterview (Convertview, R.id.app_icon);
Use very concise, will viewholder invisible.
4. Set Activity transparency
<stylename= "Transparentactivity"Parent= "Appbasetheme">
<Itemname= "Android:windowbackground">@android: Color/transparent</Item>
<Itemname= "Android:colorbackgroundcachehint">@null</Item>
<Itemname= "Android:windowistranslucent">True</Item>
<Itemname= "Android:windownotitle">True</Item>
<Itemname= "Android:windowcontentoverlay">@null</Item>
</style>
Description: Appbasetheme General is your application designated Android:theme is what here is what, otherwise activity internal space style may be inconsistent.
Use: Used to simulate dialog effects, such as the service can not be used dialog, it is possible to use activity to simulate
5. Code switch fullscreen
//Switch to full screen
GetWindow (). Clearflags (WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
Getactivity (). GetWindow (). Addflags (WindowManager.LayoutParams.FLAG_FULLSCREEN);
//switch to non-fullscreen
GetWindow (). Clearflags (WindowManager.LayoutParams.FLAG_FULLSCREEN);
GetWindow (). Addflags (WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
Note: When you switch to full screen, the virtual keys at the bottom are still displayed. The secondary method can be called multiple times for switching
Purpose: The player interface is often used
6. Call the developer option to display the Touch location feature
Android.provider.Settings.System.putInt (Getcontentresolver (), "Show_touches", 1);
Set 1 to display, setting 0 is not displayed.
7. Get a list of installed and bootable apps on your device
Intent Intent =NewIntent (Intent.action_main);
Intent.addcategory (Intent.category_launcher);
List<resolveinfo> activities = Getpackagemanager (). Queryintentactivities (Intent, 0)
Note: Using getinstalledapplications will return many system apps that cannot be started or even have no icons. ResolveInfo. Activityinfo.applicationinfo can also fetch the data you want.
Series
Android Utility Code Seven paragraph (i)
Android Utility code seven segment (ii)
Android Utility Code seven paragraph (iii)
Android Utility code seven paragraph (iv)
Android Utility Code Seven paragraph (v)