1、展开、收起状态栏 

   

public static final void collapseStatusBar(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();
}
} public static final void expandStatusBar(Context ctx) {
Object sbservice = ctx.getSystemService("statusbar");
try {
Class<?> statusBarManager = Class.forName("android.app.StatusBarManager");
Method expand;
if (Build.VERSION.SDK_INT >= ) {
expand = statusBarManager.getMethod("expandNotificationsPanel");
} else {
expand = statusBarManager.getMethod("expand");
}
expand.invoke(sbservice);
} catch (Exception e) {
e.printStackTrace();
}
}
用途:可用于点击Notifacation之后收起状态栏

2、 获取状态栏高度

  

public static int getStatusBarHeight(Context context){
Class<?> c = null;
Object obj = null;
Field field = null;
int x = , statusBarHeight = ;
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();
}
return statusBarHeight;
}

3、ListView使用ViewHolder极简写法

  

 public static <T extends View> T getAdapterView(View convertView, int id) {
SparseArray<View> viewHolder = (SparseArray<View>) convertView.getTag();
if (viewHolder == null) {
viewHolder = new SparseArray<View>();
convertView.setTag(viewHolder);
}
View childView = viewHolder.get(id);
if (childView == null) {
childView = convertView.findViewById(id);
viewHolder.put(id, childView);
}
return (T) childView;
}
用法:
@Override
public View getView(int position, 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);   用起来非常简练,将ViewHolder隐于无形。

4、 设置Activity透明

  

 <style name="TransparentActivity" parent="AppBaseTheme">
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:colorBackgroundCacheHint">@null</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowContentOverlay">@null</item>
</style>

说明:AppBaseTheme一般是你application指定的android:theme是啥这里就是啥,否则Activity内部的空间风格可能不一致。

用途:用于模拟Dialog效果,比如再Service中没法用Dialog,就可以用Activity来模拟

5、 代码切换全屏

//切换到全屏
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); //切换到非全屏
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);

注意:切换到全屏时,底部的虚拟按键仍然是显示的。次方法可多次调用用于切换


用途:播放器界面经常会用到

 

6、调用开发者选项中显示触摸位置功能

android.provider.Settings.System.putInt(getContentResolver(), "show_touches", );

设置1显示,设置0不显示。

7、获取设备上已安装并且可启动的应用列表

  

 Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER); List<ResolveInfo> activities = getPackageManager().queryIntentActivities(intent, ) 注意:使用getInstalledApplications会返回很多无法启动甚至没有图标的系统应用。ResolveInfo.activityInfo.applicationInfo也能取到你想要的数据。

Android_CodeWiki_04的更多相关文章

随机推荐

  1. mysql 取得行号后再排序

    一.理论准备 Map是键值对的集合接口,它的实现类主要包括:HashMap,TreeMap,Hashtable以及LinkedHashMap等. TreeMap:基于红黑树(Red-Black tre ...

  2. Z - 不容易系列之(3)―― LELE的RPG难题

    Description          人称“AC女之杀手”的超级偶像LELE最近忽然玩起了深沉,这可急坏了众多“Cole”(LELE的粉丝,即"可乐"),经过多方打探,某资深C ...

  3. android studio error configuration with name default not found

    Android Studio报错: android studio error configuration with name default not found 在进行sync的时候,提示Error: ...

  4. Joomla JEvents 组件

    JEvents http://extensions.joomla.org/extensions/extension/calendars-a-events/events/jevents Getting ...

  5. 一个Java项目的学习

    1. java命令行的启动 首先是gradle build 其次是:java -Dabc.appid=1234 -classpath "a.jar:b.jar"  com.ctri ...

  6. python操作redis-事务

    #!/usr/bin/python #!coding: utf-8 import redis import sys if __name__=="__main__": try: co ...

  7. SQL Server 与 Windows 内存使用上的约定

    什么时候SQL Server 会释放出自己的内存!以提供给别的程序用呢? --------------------------------------------------------------- ...

  8. Xmemcached

    http://blog.csdn.net/yuwenruli/article/details/8478201

  9. try/catch异常捕捉

    StringWriter sw = new StringWriter(); e.printStackTrace(new PrintWriter(sw)); System.out.println(sw. ...

  10. FPGA的SPI从机模块实现

    一. SPI总线协议         SPI(Serial Peripheral Interface)接口,中文为串行外设接口.它只需要3根线或4根线即可完成通信工作(这里讨论4根线的情况).     ...