zoukankan      html  css  js  c++  java
  • 小议ActionBar

     ActionBar,顾名思义,小伙伴们,你们想到了什么呢?

       嘿嘿,其实就是一个可以代替以前类似于iPhone手机导航栏效果的title在Android手机界面的位置的一种bar的设计!

        有几个事注意点哦!

        不能设置界面全局和没有标题哦!这样的话,actiobar找不到自己生存的空间,就会死掉。

        ActionBar可以自定义,也可以召唤Android里面自带的ActionBar。自定义的肯定要好多咯,不管是位置还是其他的,用着都还好啦!不过,原生的也不错。

    这里是自己写的一个简单的Actionbar,

        public void createAction() {
            // to create a SpinnerAdapter
            SpinnerAdapter adapter = ArrayAdapter.createFromResource(this,
                    R.array.style_choice,
                    android.R.layout.simple_spinner_dropdown_item);
            android.app.ActionBar actionBar = getActionBar();
    
            // to set the style
            actionBar.setDisplayShowHomeEnabled(false);
            actionBar.setDisplayShowTitleEnabled(false);
            Resources r = getResources();
    
            Drawable myDrawable = r.getDrawable(R.drawable.gradient_header);
    
            actionBar.setBackgroundDrawable(myDrawable);
    
            // to set the mode NAVIGATION_MODE_LIST
            actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
            // to add a listener
            actionBar.setListNavigationCallbacks(adapter, new DropDownListenser());
        }
    
        /**
         * 实现 ActionBar.OnNavigationListener接口
         */
        class DropDownListenser implements OnNavigationListener {
            // 得到和SpinnerAdapter里一致的字符数组
            String[] listNames = getResources()
                    .getStringArray(R.array.style_choice);
    
            /* 当选择下拉菜单项的时候,将Activity中的内容置换为对应的Fragment */
            public boolean onNavigationItemSelected(int itemPosition, long itemId) {
                if (itemPosition == 1) {
                    pager.edit().putString("name", "古典样式").commit();
                    Intent intent = new Intent().setClass(MainHomeActivity.this,
                            ClassicalMainActivity.class);
                    startActivity(intent);
                    finish();
                } else {
                    pager.edit().putString("name", "现代样式").commit();
                }
                return true;
            }
        }

    通过点击actionbar里面的内容,然后来判断页面的跳转也是可以的哦!然后也可以用一个ActionBar管住所有的应用界面哦!

    一切只是为了充实自己!!stay hungry and stay foolish!!
  • 相关阅读:
    【Gerrit】Gerrit与Jenkins/Hudson CI服务器搭建
    【Gerrit】Gerrit cmd query (gerrit命令行查询change信息)
    【python】jiraAPI使用教程 自动创建jira问题单并置状态为OPEN
    【Jenkins】jenkins简单搭建并执行任务
    【python】Redis介绍及简单使用
    【python】PIL 批量绘制图片矩形框工具
    【Flask】Flask快速玩框架
    C# split 几种使用方法
    40个有用的jQuery技术和教程
    jQuery性能优化
  • 原文地址:https://www.cnblogs.com/Catherine-Brain/p/3760630.html
Copyright © 2011-2022 走看看