2017-5-23

MainActivity

  1. public class MainActivity extends AppCompatActivity {
  2. @BindView(R.id.toolbar) Toolbar toolbar;
  3. @BindView(R.id.tabs) TabLayout tabLayout;
  4. @BindView(R.id.appbar) AppBarLayout appbar;
  5. @BindView(R.id.viewpager) ViewPager viewPager;
  6. @BindView(R.id.fab) FloatingActionButton fab;//浮动操作按钮
  7. @BindView(R.id.nav_view) NavigationView navigationView;//
  8. @BindView(R.id.drawer_layout) DrawerLayout drawerLayout;//侧滑布局
  9. @Override
  10. protected void onCreate(Bundle savedInstanceState) {
  11. super.onCreate(savedInstanceState);
  12. setContentView(R.layout.activity_main);
  13. ButterKnife.bind(this);
  14. setSupportActionBar(toolbar);
  15. getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_menu);
  16. getSupportActionBar().setDisplayHomeAsUpEnabled(true);
  17. navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
  18. @Override
  19. public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
  20. menuItem.setChecked(true);
  21. drawerLayout.closeDrawers();
  22. return true;
  23. }
  24. });
  25. Adapter adapter = new Adapter(getSupportFragmentManager());
  26. adapter.addFragment(new CheeseListFragment(), "白乾涛");
  27. adapter.addFragment(new CheeseListFragment(), "包青天");
  28. viewPager.setAdapter(adapter);
  29. tabLayout.setupWithViewPager(viewPager);
  30. }
  31. @Override
  32. public boolean onCreateOptionsMenu(Menu menu) {
  33. getMenuInflater().inflate(R.menu.sample_actions, menu);
  34. return true;
  35. }
  36. @Override
  37. public boolean onPrepareOptionsMenu(Menu menu) {
  38. switch (AppCompatDelegate.getDefaultNightMode()) {
  39. case AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM:
  40. menu.findItem(R.id.menu_night_mode_system).setChecked(true);
  41. break;
  42. case AppCompatDelegate.MODE_NIGHT_AUTO:
  43. menu.findItem(R.id.menu_night_mode_auto).setChecked(true);
  44. break;
  45. case AppCompatDelegate.MODE_NIGHT_YES:
  46. menu.findItem(R.id.menu_night_mode_night).setChecked(true);
  47. break;
  48. case AppCompatDelegate.MODE_NIGHT_NO:
  49. menu.findItem(R.id.menu_night_mode_day).setChecked(true);
  50. break;
  51. }
  52. return true;
  53. }
  54. @Override
  55. public boolean onOptionsItemSelected(MenuItem item) {
  56. switch (item.getItemId()) {
  57. case android.R.id.home:
  58. drawerLayout.openDrawer(GravityCompat.START);
  59. return true;
  60. case R.id.menu_night_mode_system:
  61. setNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
  62. break;
  63. case R.id.menu_night_mode_day:
  64. setNightMode(AppCompatDelegate.MODE_NIGHT_NO);
  65. break;
  66. case R.id.menu_night_mode_night:
  67. setNightMode(AppCompatDelegate.MODE_NIGHT_YES);
  68. break;
  69. case R.id.menu_night_mode_auto:
  70. setNightMode(AppCompatDelegate.MODE_NIGHT_AUTO);
  71. break;
  72. }
  73. return super.onOptionsItemSelected(item);
  74. }
  75. private void setNightMode(@AppCompatDelegate.NightMode int nightMode) {
  76. AppCompatDelegate.setDefaultNightMode(nightMode);
  77. if (Build.VERSION.SDK_INT >= 11) recreate();
  78. }
  79. @OnClick(R.id.fab)
  80. public void onViewClicked() {
  81. Snackbar.make(fab, "Here's a Snackbar", Snackbar.LENGTH_LONG).show();
  82. }
  83. static class Adapter extends FragmentPagerAdapter {
  84. private final List<Fragment> mFragments = new ArrayList<>();
  85. private final List<String> mFragmentTitles = new ArrayList<>();
  86. public Adapter(FragmentManager fm) {
  87. super(fm);
  88. }
  89. public void addFragment(Fragment fragment, String title) {
  90. mFragments.add(fragment);
  91. mFragmentTitles.add(title);
  92. }
  93. @Override
  94. public Fragment getItem(int position) {
  95. return mFragments.get(position);
  96. }
  97. @Override
  98. public int getCount() {
  99. return mFragments.size();
  100. }
  101. @Override
  102. public CharSequence getPageTitle(int position) {
  103. return mFragmentTitles.get(position);
  104. }
  105. }
  106. }

MainActivity布局

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. xmlns:app="http://schemas.android.com/apk/res-auto"
  4. android:id="@+id/drawer_layout"
  5. android:layout_width="match_parent"
  6. android:layout_height="match_parent"
  7. android:fitsSystemWindows="true">
  8. <include layout="@layout/include_list_viewpager"/>
  9. <!--侧滑布局-->
  10. <android.support.design.widget.NavigationView
  11. android:id="@+id/nav_view"
  12. android:layout_width="wrap_content"
  13. android:layout_height="match_parent"
  14. android:layout_gravity="start"
  15. android:fitsSystemWindows="true"
  16. app:headerLayout="@layout/nav_header"
  17. app:menu="@menu/drawer_view"/>
  18. </android.support.v4.widget.DrawerLayout>

MainActivity内容区域布局

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. xmlns:app="http://schemas.android.com/apk/res-auto"
  4. android:id="@+id/main_content"
  5. android:layout_width="match_parent"
  6. android:layout_height="match_parent">
  7. <android.support.design.widget.AppBarLayout
  8. android:id="@+id/appbar"
  9. android:layout_width="match_parent"
  10. android:layout_height="wrap_content"
  11. android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
  12. <android.support.v7.widget.Toolbar
  13. android:id="@+id/toolbar"
  14. android:layout_width="match_parent"
  15. android:layout_height="?attr/actionBarSize"
  16. android:background="?attr/colorPrimary"
  17. app:layout_scrollFlags="scroll|enterAlways|snap"
  18. app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
  19. <android.support.design.widget.TabLayout
  20. android:id="@+id/tabs"
  21. android:layout_width="match_parent"
  22. android:layout_height="wrap_content"/>
  23. </android.support.design.widget.AppBarLayout>
  24. <android.support.v4.view.ViewPager
  25. android:id="@+id/viewpager"
  26. android:layout_width="match_parent"
  27. android:layout_height="match_parent"
  28. app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
  29. <android.support.design.widget.FloatingActionButton
  30. android:id="@+id/fab"
  31. android:layout_width="wrap_content"
  32. android:layout_height="wrap_content"
  33. android:layout_gravity="end|bottom"
  34. android:layout_margin="@dimen/fab_margin"
  35. android:src="@drawable/ic_done"/>
  36. </android.support.design.widget.CoordinatorLayout>

Fragment

  1. public class CheeseListFragment extends Fragment {
  2. @Override
  3. public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  4. RecyclerView recyclerView = (RecyclerView) inflater.inflate(R.layout.fragment_cheese_list, container, false);
  5. recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
  6. recyclerView.setAdapter(new MyAdapter(getActivity(), getRandomSublist()));
  7. return recyclerView;
  8. }
  9. private List<String> getRandomSublist() {
  10. String[] array = Cheeses.sCheeseStrings;
  11. ArrayList<String> list = new ArrayList<String>();
  12. while (list.size() < 30) {
  13. list.add(array[new Random().nextInt(array.length)]);
  14. }
  15. return list;
  16. }
  17. }

Adapter

  1. public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder> {
  2. private List<String> mList;
  3. private Context context;
  4. public MyAdapter(Context context, List<String> mList) {
  5. this.mList = mList;
  6. this.context = context;
  7. }
  8. @Override
  9. public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
  10. return new ViewHolder(LayoutInflater.from(context).inflate(R.layout.list_item, parent, false));
  11. }
  12. @Override
  13. public void onBindViewHolder(final ViewHolder holder, int position) {
  14. holder.mTextView.setText(mList.get(position));
  15. holder.ll_item.setOnClickListener(new View.OnClickListener() {
  16. @Override
  17. public void onClick(View v) {
  18. Intent intent = new Intent(context, CheeseDetailActivity.class);
  19. intent.putExtra(CheeseDetailActivity.EXTRA_NAME, mList.get(holder.getAdapterPosition()));
  20. context.startActivity(intent);
  21. }
  22. });
  23. Glide.with(holder.mImageView.getContext())
  24. .load(Cheeses.getRandomCheeseDrawable())
  25. .fitCenter()
  26. .into(holder.mImageView);
  27. }
  28. @Override
  29. public int getItemCount() {
  30. return mList.size();
  31. }
  32. static class ViewHolder extends RecyclerView.ViewHolder {
  33. @BindView(R.id.avatar) CircleImageView mImageView;
  34. @BindView(R.id.text) TextView mTextView;
  35. @BindView(R.id.ll_item) View ll_item;
  36. ViewHolder(View view) {
  37. super(view);
  38. ButterKnife.bind(this, view);
  39. }
  40. }
  41. }
2017-5-23

附件列表

一个十分简洁实用的MD风格的UI主框架的更多相关文章

  1. Android 模仿QQ风格的 UI

    本文内容 环境 演示模仿QQ风格的界面 本文主要演示的是 UI,如何模仿 QQ 风格的界面.虽然这个 UI 跟现在的QQ空间有点差别,但是也能学到很多东西. 下载 Demo 环境 Windows 7 ...

  2. LTUI v1.1, 一个基于lua的跨平台字符终端UI界面库

    简介 LTUI是一个基于lua的跨平台字符终端UI界面库. 此框架源于xmake中图形化菜单配置的需求,类似linux kernel的menuconf去配置编译参数,因此基于curses和lua实现了 ...

  3. [C语言]一个很实用的服务端和客户端进行TCP通信的实例

    本文给出一个很实用的服务端和客户端进行TCP通信的小例子.具体实现上非常简单,只是平时编写类似程序,具体步骤经常忘记,还要总是查,暂且将其记下来,方便以后参考. (1)客户端程序,编写一个文件clie ...

  4. Android 模仿QQ空间风格的 UI(转)

    本文内容 环境 演示模仿QQ空间风格的UI 虽然这个 UI 跟现在的QQ空间有点差别,但是也能学到很多东西. 下载 Demo 环境 Windows 7 64 位 Eclipse ADT V22.6.2 ...

  5. Android 模仿QQ空间风格的 UI

    本文内容 环境 演示模仿QQ空间风格的UI 虽然这个 UI 跟现在的QQ空间有点差别,但是也能学到很多东西. 下载 Demo 环境 Windows 7 64 位 Eclipse ADT V22.6.2 ...

  6. 各种Android UI开源框架 开源库

    各种Android UI开源框架 开源库 转 https://blog.csdn.net/zhangdi_gdk2016/article/details/84643668 自己总结的Android开源 ...

  7. 10个顶级的CSS UI开源框架

    随着CSS3和HTML5的流行,我们的WEB页面不仅需要更人性化的设计理念,而且需要更酷的页面特效和用户体验.作为开发者,我们需要了解一些宝贵的CSS UI开源框架资源,它们可以帮助我们更快更好地实现 ...

  8. web前端开发常用的10个高端CSS UI开源框架

    web前端开发常用的10个高端CSS UI开源框架   随着人们对体验的极致追求,web页面设计也面临着新的挑战,不仅需要更人性化的设计理念,还需要设计出更酷炫的页面.作为web前端开发人员,运用开源 ...

  9. [转]10个顶级的CSS UI开源框架

    随着CSS3和HTML5的流行,我们的WEB页面不仅需要更人性化的设计理念,而且需要更酷的页面特效和用户体验.作为开发者,我们需要了解一些宝贵的CSS UI开源框架资源,它们可以帮助我们更快更好地实现 ...

随机推荐

  1. ES6 简介

    1.全称: ECMA 标准,又称ES2015 JavaScript 是大家所了解的语言名称,但是这个语言名称是商标( Oracle 公司注册的商标).因此,JavaScript 的正式名称是 ECMA ...

  2. QString 与中文问题

    原文请看:http://www.cnblogs.com/phoenixlaozhu/articles/2553180.html (更新:本文的姊妹篇Qt5与中文问题) 首先呢,声明一下,QString ...

  3. Android中xml tool属性

    http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2015/0309/2567.html 我是搬运工.. 总结而言tool属性就是为了在IDE ...

  4. 批量 添加 安卓构建 版本 eclipse

    韩梦飞沙  韩亚飞  313134555@qq.com  yue31313  han_meng_fei_sha

  5. 62.COUNT(递归算法)--数的划分变式题型

    文件名:count.cpp 输入输出文件:count.in.count.out 时空:64M,2s 我们已经知道这样一个定理:任意一个正整数能够分解成最多4个数字的平方和.现在给你一些数字,要你求出它 ...

  6. 《深入理解Spark-核心思想与源码分析》(六)第六章计算引擎

    RDD是Spark对各类数据计算模型的统一抽象,被用于迭代计算过程以及任务输出结果的缓存读写. 在所有MapReduce框架中,shuffle是连接map任务和reduce任务的桥梁.shuffle性 ...

  7. URAL 1995 Illegal spices 贪心构造

    Illegal spices 题目连接: http://acm.timus.ru/problem.aspx?space=1&num=1995 Description Jabba: Han, m ...

  8. HDU 5644 King's Pilots 费用流

    King's Pilots 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5644 Description The military parade w ...

  9. 微信小程序的坑

    虽然官方文档,可以在.json中给页面设置背景颜色,用backgroundColor,但是实际上并不好使,所以设置背景颜色只能在wxss中设置 <import src="../comm ...

  10. MariaDB Audit Plugin 1.2

    下载地址:https://downloads.mariadb.com/enterprise/bbfz-atd2/mariadb-audit-plugin/server_audit-1.2.0.tar. ...