Navigation drawer details-controls released by Google to replace sliding menu (2

Source: Internet
Author: User

      第一篇我们就google官方给出的Navigation Drawer demo做了一个简单的介绍,细心的童鞋可能已经发现问题了,google虽然是在support v4中添加的这个控件,但是他给的demo中却使用了ActionBar!ActionBar是在3.0才出现的控件,我们如果想在2.X的版本上同时使用ActionBar和Navigation Drawer,该怎么办呢?http://www.ijiami.cn/treg

      其实这个也很简单,我们只需要使用一个开源的library就可以完成了:ActionBarSherlock。ActionBarSherlock的具体用法大家可以参照我的另外一篇教程:
http://www.apkbus.com/forum.php?mod=viewthread&tid=121101


      我们首先导入ActionBarSherlock:




然后修改MainActivity,让它继承ActionBarSherlock中的SherlockFragmentActivity:

  • public class MainActivity extends SherlockFragmentActivity


[color=#336699 !important]复制代码

然后把所有的getActionBar修改为getSupportActionBar:

  •                 // Enable ActionBar app icon to behave as action to toggle nav drawer

  •                 getSupportActionBar().setHomeButtonEnabled(true);

  •                 getSupportActionBar().setDisplayHomeAsUpEnabled(true);


[color=#336699 !important]复制代码



修改完这些,我们就已经可以在2.X的系统上实现ActionBar的效果了。
大家看看运行的:





Navigation Drawer详解-Google推出的用来取代Sliding Menu的控件(二

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.