Action Bar是android3.0以后才引入的,主要是替代3.0以前的menu和tittle bar。在3.0之前是不能使用Action Bar功能的。这里引入了自定义的Action Bar,自定义Action bar也不是完全实现了 Action bar功能,只是在外形上相似。自定义Action bar没有实现overflow button(悬浮按钮)的功能,如果想进一步实现overflow button功能,可参考Android UI开发第十六篇――分享一个popuwindow实例.

xml

 <com.nedu.android.widget.ActionBar     android:id="@+id/actionbar"     app:title="@string/some_title"     style="@style/ActionBar"         />

app:title 可选,也可以在使用时设置,actionBar.setTitle("Home")。
在Activity中,HomeAction处于Bar的最左侧,普通Action处于Bar的最右侧

        ActionBar actionBar = (ActionBar) findViewById(R.id.actionbar);         // You can also assign the title programmatically by passing a         // CharSequence or resource id.         //actionBar.setTitle(R.string.some_title);         actionBar.setHomeAction(new IntentAction(this, HomeActivity.createIntent(this), R.drawable.ic_title_home_default));         actionBar.setDisplayHomeAsUpEnabled(true);         actionBar.addAction(new IntentAction(this, createShareIntent(), R.drawable.ic_title_share_default));         actionBar.addAction(new ExampleAction());
自定义Action 创建自定义Action 仅需要实现一个Action接口,例如ExampleAction:
  private class ExampleAction extends AbstractAction {          public ExampleAction() {             super(R.drawable.ic_title_export_default);         }          @Override         public void performAction(View view) {             Toast.makeText(OtherActivity.this,                     "Example action", Toast.LENGTH_SHORT).show();         }      }

如果想修改UI属性可修改drawable、layout、values里面的文件。



代码:http://download.csdn.net/detail/xyz_lmn/4710843


/**
* @author 张兴业
* 邮箱:xy-zhang#163.com
* android开发进阶群:278401545
*
*/


更多相关文章

  1. android当中的xml没有代码提示功能解决办法
  2. [Android]滑动刷新ListView——android-pulltorefresh使用方法解
  3. android图片涂鸦,具有设置画笔,撤销,缩放移动等功能(一)
  4. freescale Android(安卓)Camera 调试总结
  5. Android学习进阶和IoC
  6. Android四大功能组件深入分析
  7. 5、frida进阶-Android逆向之旅---Hook神器家族的Frida工具使用详
  8. Android高手进阶教程(二)之----Android(安卓)Launcher抽屉类Slid
  9. Android常用功能实例 如IMEI号

随机推荐

  1. Android中StackView的使用
  2. 调用Android installer 安装和卸载程序
  3. Android(安卓)自定义控件,模仿小米秒表样
  4. android动态生成控件
  5. Android发送dtmf键盘事件(模拟通话界面键
  6. Android 3D 旋转的三角形(三)
  7. Android解压中文乱码
  8. android studio 读取短信
  9. android:软件的安装和卸载源代码
  10. React Native与Android之间的通信