当前位置: 代码迷 >> Android >> android自定义状态栏!一
  详细解决方案

android自定义状态栏!一

热度:53   发布时间:2016-04-27 23:32:38.0
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);  } }

最终的效果:



版权声明:本文为博主原创文章,未经博主允许不得转载。

  相关解决方案