知识分享:
首先看图,我只是大自然的搬运工,想实现这种特效的请点击连接下载github地址忘掉了,。。。。http://download.csdn.net/detail/lj419855402/8602281
主要实现代码,利用AS编译。
package net.xpece.material.navigationdrawer.sample.ui; import android.annotation.SuppressLint;
import android.content.res.Configuration;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBarDrawerToggle;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast; import com.sqisland.android.sliding_pane_layout.CrossFadeSlidingPaneLayout; import net.xpece.material.navigationdrawer.NavigationDrawerUtils;
import net.xpece.material.navigationdrawer.descriptors.BaseNavigationItemDescriptor;
import net.xpece.material.navigationdrawer.descriptors.NavigationItemDescriptor;
import net.xpece.material.navigationdrawer.descriptors.NavigationSectionDescriptor;
import net.xpece.material.navigationdrawer.descriptors.SimpleNavigationItemDescriptor;
import net.xpece.material.navigationdrawer.internal.Utils;
import net.xpece.material.navigationdrawer.list.NavigationListFragmentCallbacks;
import net.xpece.material.navigationdrawer.list.SupportCompactNavigationListFragment;
import net.xpece.material.navigationdrawer.list.SupportNavigationListFragment;
import net.xpece.material.navigationdrawer.sample.widget.ToggleNavigationItemDescriptor;
import net.xpece.materialnavigationdrawersample.BuildConfig;
import net.xpece.materialnavigationdrawersample.R; import java.util.ArrayList;
import java.util.List; import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.Optional;
import timber.log.Timber; public class MainActivity extends ActionBarActivity implements NavigationListFragmentCallbacks { // @InjectView(R.id.app_bar)
// Toolbar mToolbar; private static final List<NavigationSectionDescriptor> SECTIONS = new ArrayList<>();
private static final NavigationSectionDescriptor PRIMARY_SECTION;
private static final NavigationSectionDescriptor PINNED_SECTION; static {
PRIMARY_SECTION = new NavigationSectionDescriptor()
.addItem(new SimpleNavigationItemDescriptor(1).text("Goodbye").badge("Hello").sticky()
.iconResource(R.drawable.ic_star_black_24dp)
.activeColorResource(R.color.material_red_500)
.badgeColorResource(R.color.material_red_500))
.addItem(new SimpleNavigationItemDescriptor(2).text("Yes").badge("No").sticky()
.iconResource(R.drawable.ic_star_black_24dp)
.passiveColorResource(R.color.material_amber_500).iconColorAlwaysPassiveOn()
.badgeColorResource(R.color.material_amber_500))
.addItem(new SimpleNavigationItemDescriptor(3).text("Stop").badge("Go, go, go").sticky()
// .iconResource(R.drawable.ic_star_black_24dp)
.iconResource(android.R.color.transparent)
.activeColorResource(R.color.material_light_green_500)
.badgeColorResource(R.color.material_light_green_500))
.addItem(new SimpleNavigationItemDescriptor(4).text("Why").badge("I don't know").sticky()
.iconResource(0)
.activeColorResource(R.color.material_light_blue_500).iconColorAlwaysPassiveOn()
.badgeColor(0));
SECTIONS.add(PRIMARY_SECTION);
NavigationSectionDescriptor section2 = new NavigationSectionDescriptor().heading("Want more?")
.addItem(new ToggleNavigationItemDescriptor(8).checked(true));
SECTIONS.add(section2);
NavigationSectionDescriptor section3 = new NavigationSectionDescriptor()
.addItem(new BaseNavigationItemDescriptor(6).text("Settings")
.iconResource(R.drawable.ic_settings_black_24dp))
.addItem(new BaseNavigationItemDescriptor(7).text("Help & feedback")
.iconResource(R.drawable.ic_help_black_24dp));
PINNED_SECTION = section3; if (BuildConfig.DEBUG) Timber.plant(new Timber.DebugTree());
} @Optional
@InjectView(R.id.drawer_layout)
DrawerLayout mDrawerLayout; @Optional
@InjectView(R.id.sliding_layout)
CrossFadeSlidingPaneLayout mSlidingLayout; @Optional
@InjectView(R.id.navigation_container)
ViewGroup mNavigationContainer; @InjectView(R.id.content)
View mContent; ActionBarDrawerToggle mDrawerToggle; SupportNavigationListFragment mNavFragment;
SupportCompactNavigationListFragment mNavFragmentCompact; // retain this
Long mSelectedItem; // so I can show new toast immediately
Toast mToast = null; @SuppressLint("RtlHardcoded")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.inject(this); // only setup drawer layout if there is a drawer in current layout (on phones)
if (mDrawerLayout != null) {
// setup drawer toggle, because i use native Action Bar and nav drawer below it
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, android.R.string.untitled, android.R.string.untitled);
mDrawerLayout.setDrawerListener(mDrawerToggle); NavigationDrawerUtils.fixMinDrawerMargin(mDrawerLayout); // apply navigation margin fix // the following are correct the RIGHT drawer drops shadow to LEFT and vice versa
mDrawerLayout.setDrawerShadow(R.drawable.mnd_shadow_left, Gravity.RIGHT);
mDrawerLayout.setDrawerShadow(R.drawable.mnd_shadow_right, Gravity.LEFT);
} // only setup sliding layout if there is one in current layout (on tablets)
if (mSlidingLayout != null) {
mSlidingLayout.setSliderFadeColor(0);
mSlidingLayout.setShadowResourceLeft(R.drawable.mnd_shadow_left);
mSlidingLayout.setShadowResourceRight(R.drawable.mnd_shadow_right);
NavigationDrawerUtils.setProperNavigationDrawerWidth(mNavigationContainer); Drawable d = getResources().getDrawable(R.drawable.ic_menu_white_24dp);
int c = Utils.getColor(getSupportActionBar().getThemedContext(), R.attr.colorControlNormal, 0);
d = Utils.tintDrawable(d, c);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeAsUpIndicator(d);
} // on phones there is no compact version, so null check is in place
mNavFragmentCompact = (SupportCompactNavigationListFragment) getSupportFragmentManager().findFragmentById(R.id.navigation_drawer_compact);
if (mNavFragmentCompact != null) {
List<NavigationSectionDescriptor> sections = new ArrayList<>();
sections.add(PRIMARY_SECTION);
sections.add(PINNED_SECTION);
mNavFragmentCompact.setHeaderView(View.inflate(this, R.layout.mnd_custom_header_compact, null), false);
mNavFragmentCompact.setSections(sections);
} // since the fragment is defined in layout, i can call this safely in onCreate
mNavFragment = (SupportNavigationListFragment) getSupportFragmentManager().findFragmentById(R.id.navigation_drawer);
if (mNavFragment != null) {
NavigationDrawerUtils.setProperNavigationDrawerWidth(mNavFragment.getView());
// set up the nav fragment
mNavFragment.setHeaderView(View.inflate(this, R.layout.mnd_custom_header, null), true);
mNavFragment.setSections(SECTIONS);
mNavFragment.setPinnedSection(PINNED_SECTION); mNavFragment.setBackgroundResource(R.drawable.a7x_aligned);
} if (savedInstanceState == null) {
mSelectedItem = 1l;
} else {
mSelectedItem = savedInstanceState.getLong("mSelectedItem");
}
} @Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState); if (mDrawerToggle != null) mDrawerToggle.syncState(); if (savedInstanceState == null) {
if (mNavFragment != null) mNavFragment.setSelectedItem(mSelectedItem);
if (mNavFragmentCompact != null) mNavFragmentCompact.setSelectedItem(mSelectedItem);
}
} @Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig); if (mDrawerToggle != null) mDrawerToggle.onConfigurationChanged(newConfig);
} @Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putLong("mSelectedItem", mSelectedItem);
} @Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
} @Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
// AUTOMATICALLY ONLY ON 4.1+ !!! int id = item.getItemId(); //noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
} else if (id == android.R.id.home) {
if (mDrawerToggle != null) return mDrawerToggle.onOptionsItemSelected(item);
if (mSlidingLayout != null) {
if (mSlidingLayout.isOpen()) mSlidingLayout.closePane();
else mSlidingLayout.openPane();
return true;
}
} return super.onOptionsItemSelected(item);
} @Override
public void onNavigationItemSelected(View view, int position, long id, NavigationItemDescriptor item) {
if (mToast != null) mToast.cancel();
mToast = Toast.makeText(this, "Item #" + id + " on position " + position + " selected!", Toast.LENGTH_SHORT);
mToast.show(); if (item != null && item.isSticky()) {
// if it is sticky, save selected position and mark in all fragments
mSelectedItem = id;
if (mNavFragment != null) mNavFragment.setSelectedItem(id);
if (mNavFragmentCompact != null) mNavFragmentCompact.setSelectedItem(id);
} else {
// if (mNavFragment != null) mNavFragment.setSelectedItem(id);
// if (mNavFragmentCompact != null) mNavFragmentCompact.setSelectedItem(id);
} if (id == 8) return; // custom toggle does not close the drawer // if (mDrawerLayout != null) mDrawerLayout.closeDrawers(); // uncomment to close drawer on item selected
} }
github上一款特别的侧滑的更多相关文章
-
GitHub 上 57 款最流行的开源深度学习项目
转载:https://www.oschina.net/news/79500/57-most-popular-deep-learning-project-at-github GitHub 上 57 款最 ...
-
GitHub 上 57 款最流行的开源深度学习项目【转】
GitHub 上 57 款最流行的开源深度学习项目[转] 2017-02-19 20:09 334人阅读 评论(0) 收藏 举报 分类: deeplearning(28) from: https:// ...
-
GitHub 上 10 款免费开源 Windows 工具
GitHub 上 10 款免费开源 Windows 工具 GitHub 是如今所有开源事物的*仓库, 这个网站最近发布了一个叫做<2016 Octoverse 状态报告>,详细列出了从 ...
-
Github上关于iOS的各种开源项目集合(强烈建议大家收藏,查看,总有一款你需要)
下拉刷新 EGOTableViewPullRefresh - 最早的下拉刷新控件. SVPullToRefresh - 下拉刷新控件. MJRefresh - 仅需一行代码就可以为UITableVie ...
-
28款GitHub最流行的开源机器学习项目,推荐GitHub上10 个开源深度学习框架
20 个顶尖的 Python 机器学习开源项目 机器学习 2015-06-08 22:44:30 发布 您的评价: 0.0 收藏 1收藏 我们在Github上的贡献者和提交者之中检查了用Python语 ...
-
【转】10款GitHub上最火爆的国产开源项目
将开源做到极致,提高效率方便更多用户 接触开源时间虽然比较短但是后续会努力为开源社区贡献自己微薄的力量 衡量一个开源产品好不好,看看产品在 GitHub 的 Star 数量就知道了.由此可见,GitH ...
-
Github上关于iOS的各种开源项目集合2(强烈建议大家收藏,查看,总有一款你需要)
资源list:Github上关于大数据的开源项目.论文等合集 Awesome Big Data A curated list of awesome big data frameworks, resou ...
-
点评10款Github上最火爆的国产开源项目
衡量一个开源产品好不好,看看产品在Github的Star数量就知道了.由此可见,Github已经沦落为开源产品的“大众点评”了. 一个开源产品希望快速的被开发者知道.快速的获取反馈,放到Github上 ...
-
GitHub 上的十一款热门开源安全工具
作为开源开发领域的基石,“所有漏洞皆属浅表”已经成为一条著名的原则甚至是信条.作为广为人知的Linus定律,当讨论开源模式在安全方面的优势时,开放代码能够提高项目漏洞检测效率的理论也被IT专业人士们所 ...
随机推荐
-
读《深入理解Java虚拟机》有感——第一部分:Class文件的结构
1.产生 源码(.java文件)——>编译器(如:javac)——>字节码(.class文件)——>虚拟机(如:HotSpot)执行 2.Class文件 1)构成: ...
-
ssh隧道技术
大家都知道SSH是一种安全的传输协议,用在连接服务器上比较多.不过其实除了这个功能,它的隧道转发功能更是吸引人.下面是个人根据自己的需求以及在网上查找的资料配合自己的实际操作所得到的一些心得. SSH ...
-
visual studio F12 失效,可能是装了插件,比如ReSharper 但是,ReSharper没有激活导致.
visual studio F12 失效,可能是装了插件,比如ReSharper 但是,ReSharper没有激活导致.
-
转:Ext GridPanel根据条件显示复选框
Ext GridPanel实现复选框选择框: var selectModel = new Ext.grid.CheckboxSelectionModel({ singleSelect : false ...
-
js正则验证手机号码有效性
验证130-139,150-159,180-189号码段的手机号码 <script type="text/javascript"> [-]{})|([-]{})|([- ...
-
Servlet Cookie取不到值原因
现象: 在测试带Cookie的HTTP请求时发现,服务端用request.getHeader("cookie")可以去到值; 但是用request.getCookies()却不行 ...
-
java模板设计模式
1.概述 模板设计模式定义:定义一个操作中的算法骨架,将步骤延迟到子类中. 模板设计模式是一种行为设计模式,一般是准备一个抽象类,将部分逻辑以具体方法或者具体的构造函数实现,然后声明一些抽象方法,这样 ...
-
跟我学SharePoint2013视频培训课程——设置列表名称、描述、导航等基本信息(12)
课程简介 第12天,怎样在SharePoint 2013设置列表名称.描述.导航等基本信息. 视频 SharePoint 2013 交流群 41032413
-
WPF全屏
https://blog.onedevjob.com/2010/10/19/fixing-full-screen-wpf-windows/ 让窗口重绘 Visibility = Visibility. ...
-
利用纯JS和HTML Canvas生成随机迷宫过程中产生的有趣的事情
上效果图: #先看生成随机迷宫的代码吧↓ <html> <head> <title>生成随机迷宫v1.0</title> </head> & ...