ActionBarSherlock学习笔记——ActionBar添加View

来源:互联网 发布:站长seo查询 编辑:程序博客网 时间:2024/05/18 01:31

为ActionBar添加View

1.添加一个RadioGroup

 1         /** 2          * 通过解析获得一个view布局 3          */ 4         View customNav = LayoutInflater.from(this).inflate( 5                 R.layout.custom_view, null); 6  7         /** 8          * 为解析的布局中的view添加监听事件 9          */10         ((RadioGroup) customNav.findViewById(R.id.radio_nav))11                 .setOnCheckedChangeListener(new OnCheckedChangeListener() {12                     @Override13                     public void onCheckedChanged(RadioGroup group, int checkedId) {14                         Toast.makeText(CustomNavigation.this,15                                 "Navigation selection changed.",16                                 Toast.LENGTH_SHORT).show();17                     }18                 });19 20         /**21          * 添加到ActionBar中,这个添加的view,由左向右布局22          */23         getSupportActionBar().setCustomView(customNav);24         /**25          * 设置是否显示添加的View26          */27         getSupportActionBar().setDisplayShowCustomEnabled(true);

源码下载地址  https://github.com/JakeWharton/ActionBarSherlock

0 0
原创粉丝点击