ActionBarSherlock学习笔记——ActionBar添加View

为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                     @Override
13                     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          * 设置是否显示添加的View
26          */
27         getSupportActionBar().setDisplayShowCustomEnabled(true);

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

posted @ 2013-05-07 14:42  有情怀的人  阅读(427)  评论(0)    收藏  举报