1,VectorDrawable,矢量图的支持,不深入了解,作为了解,挺好玩的。
TasksFragment tasksFragment = (TasksFragment) getSupportFragmentManager().findFragmentById(R.id.contentFrame);
if (tasksFragment == null) { // Create the fragment tasksFragment = TasksFragment.newInstance(); ActivityUtils.addFragmentToActivity( getSupportFragmentManager(), tasksFragment, R.id.contentFrame); }
2,给activiy添加fragment,findFragmentById(id) id可以是fragment的id 也可以是一个布局容器,FragmentManager是一个管理fragment的队列,也保存fragment的状态,搜索一些资料说,fragment的启动更快,替activity分担了一些任务,而且可以针对手机和平板设置不同的布局。
3,DrawerLayout 嵌套NavigationView 侧滑动
<android.support.design.widget.NavigationView android:id="@+id/nav_view" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_gravity="start" android:fitsSystemWindows="true" app:headerLayout="@layout/nav_header" app:menu="@menu/drawer_actions" />NavigationView 装载头布局 和 menu布局
if (navigationView != null) { // Init navigationView setupDrawerContent(navigationView); }
private void setupDrawerContent(NavigationView navigationView) { navigationView.setNavigationItemSelectedListener( new NavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(MenuItem menuItem) { switch (menuItem.getItemId()) { case R.id.list_navigation_menu_item: // Do nothing, we're already on that screen break; case R.id.statistics_navigation_menu_item: Intent intent = new Intent(TasksActivity.this, StatisticsActivity.class); startActivity(intent); break; default: break; } // Close the navigation drawer when an item is selected. menuItem.setChecked(true); mDrawerLayout.closeDrawers(); return true; } }); }
5,ActionBar 也挺好用的
ActionBar ab = getSupportActionBar(); //Set ActionBar left icon ab.setHomeAsUpIndicator(R.drawable.ic_menu); ab.setDisplayHomeAsUpEnabled(true);设置左侧图标