zoukankan      html  css  js  c++  java
  • Android UI开发第二十五篇——分享一篇自定义的 Action Bar

           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
    *
    */


  • 相关阅读:
    golang访问数据库
    dynamic与泛型
    新的published和$M+对比
    插入窗体到别的程序里
    淺談怎么样运用Delphi 2009地泛型容器類別
    Delphi随记
    查找文件
    Delphi操作xml
    Delphi图像编程学习笔记
    Ext.net中如何上传文件
  • 原文地址:https://www.cnblogs.com/xyzlmn/p/3168080.html
Copyright © 2011-2022 走看看