android自己定义状态栏!!1
1.首先去掉原先系统自带的actionBar,在api 11 后才出现actionBar的概念,在v11的value的style.xml的文件里改动,假设没有的话默认的value就是v11
<!-- Application theme. --> <style name="AppTheme" parent="AppBaseTheme"> <!-- All customizations that are NOT specific to a particular API-level can go here. --> <item name="android:actionBarStyle">@style/myActvionBar</item> </style> <style name="myActvionBar" parent="@android:style/Widget.Holo.Light.ActionBar"> <!-- 去掉actionBar的左边图标 --> <item name="android:displayOptions">@null</item> </style>
2.在layout目录中写出actionBar的布局文件
3.在Java代码中载入布局
/** * 设置ActionBar * @param context * @param layoutId */ public static void setActonBarLayout(Context context,int layoutId) { ActionBar actionBar = ((Activity)context).getActionBar(); if (actionBar != null) { actionBar.setDisplayShowHomeEnabled(false); actionBar.setDisplayShowCustomEnabled(true); LayoutInflater layoutInflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); View v = layoutInflater.inflate(layoutId, null); ActionBar.LayoutParams layoutParams = new ActionBar.LayoutParams( LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); v.setLayoutParams(layoutParams); actionBar.setCustomView(v); } }
终于的效果: