一个十分简洁实用的MD风格的UI主框架
MainActivity
public class MainActivity extends AppCompatActivity {@BindView(R.id.toolbar) Toolbar toolbar;@BindView(R.id.tabs) TabLayout tabLayout;@BindView(R.id.appbar) AppBarLayout appbar;@BindView(R.id.viewpager) ViewPager viewPager;@BindView(R.id.fab) FloatingActionButton fab;//浮动操作按钮@BindView(R.id.nav_view) NavigationView navigationView;//@BindView(R.id.drawer_layout) DrawerLayout drawerLayout;//侧滑布局@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);ButterKnife.bind(this);setSupportActionBar(toolbar);getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_menu);getSupportActionBar().setDisplayHomeAsUpEnabled(true);navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {@Overridepublic boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {menuItem.setChecked(true);drawerLayout.closeDrawers();return true;}});Adapter adapter = new Adapter(getSupportFragmentManager());adapter.addFragment(new CheeseListFragment(), "白乾涛");adapter.addFragment(new CheeseListFragment(), "包青天");viewPager.setAdapter(adapter);tabLayout.setupWithViewPager(viewPager);}@Overridepublic boolean onCreateOptionsMenu(Menu menu) {getMenuInflater().inflate(R.menu.sample_actions, menu);return true;}@Overridepublic boolean onPrepareOptionsMenu(Menu menu) {switch (AppCompatDelegate.getDefaultNightMode()) {case AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM:menu.findItem(R.id.menu_night_mode_system).setChecked(true);break;case AppCompatDelegate.MODE_NIGHT_AUTO:menu.findItem(R.id.menu_night_mode_auto).setChecked(true);break;case AppCompatDelegate.MODE_NIGHT_YES:menu.findItem(R.id.menu_night_mode_night).setChecked(true);break;case AppCompatDelegate.MODE_NIGHT_NO:menu.findItem(R.id.menu_night_mode_day).setChecked(true);break;}return true;}@Overridepublic boolean onOptionsItemSelected(MenuItem item) {switch (item.getItemId()) {case android.R.id.home:drawerLayout.openDrawer(GravityCompat.START);return true;case R.id.menu_night_mode_system:setNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);break;case R.id.menu_night_mode_day:setNightMode(AppCompatDelegate.MODE_NIGHT_NO);break;case R.id.menu_night_mode_night:setNightMode(AppCompatDelegate.MODE_NIGHT_YES);break;case R.id.menu_night_mode_auto:setNightMode(AppCompatDelegate.MODE_NIGHT_AUTO);break;}return super.onOptionsItemSelected(item);}private void setNightMode(@AppCompatDelegate.NightMode int nightMode) {AppCompatDelegate.setDefaultNightMode(nightMode);if (Build.VERSION.SDK_INT >= 11) recreate();}@OnClick(R.id.fab)public void onViewClicked() {Snackbar.make(fab, "Here's a Snackbar", Snackbar.LENGTH_LONG).show();}static class Adapter extends FragmentPagerAdapter {private final List<Fragment> mFragments = new ArrayList<>();private final List<String> mFragmentTitles = new ArrayList<>();public Adapter(FragmentManager fm) {super(fm);}public void addFragment(Fragment fragment, String title) {mFragments.add(fragment);mFragmentTitles.add(title);}@Overridepublic Fragment getItem(int position) {return mFragments.get(position);}@Overridepublic int getCount() {return mFragments.size();}@Overridepublic CharSequence getPageTitle(int position) {return mFragmentTitles.get(position);}}}
MainActivity布局
<?xml version="1.0" encoding="utf-8"?><android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"android:id="@+id/drawer_layout"android:layout_width="match_parent"android:layout_height="match_parent"android:fitsSystemWindows="true"><include layout="@layout/include_list_viewpager"/><!--侧滑布局--><android.support.design.widget.NavigationViewandroid: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_view"/></android.support.v4.widget.DrawerLayout>
MainActivity内容区域布局
<?xml version="1.0" encoding="utf-8"?><android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"android:id="@+id/main_content"android:layout_width="match_parent"android:layout_height="match_parent"><android.support.design.widget.AppBarLayoutandroid:id="@+id/appbar"android:layout_width="match_parent"android:layout_height="wrap_content"android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"><android.support.v7.widget.Toolbarandroid:id="@+id/toolbar"android:layout_width="match_parent"android:layout_height="?attr/actionBarSize"android:background="?attr/colorPrimary"app:layout_scrollFlags="scroll|enterAlways|snap"app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/><android.support.design.widget.TabLayoutandroid:id="@+id/tabs"android:layout_width="match_parent"android:layout_height="wrap_content"/></android.support.design.widget.AppBarLayout><android.support.v4.view.ViewPagerandroid:id="@+id/viewpager"android:layout_width="match_parent"android:layout_height="match_parent"app:layout_behavior="@string/appbar_scrolling_view_behavior"/><android.support.design.widget.FloatingActionButtonandroid:id="@+id/fab"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="end|bottom"android:layout_margin="@dimen/fab_margin"android:src="@drawable/ic_done"/></android.support.design.widget.CoordinatorLayout>
Fragment
public class CheeseListFragment extends Fragment {@Overridepublic View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {RecyclerView recyclerView = (RecyclerView) inflater.inflate(R.layout.fragment_cheese_list, container, false);recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));recyclerView.setAdapter(new MyAdapter(getActivity(), getRandomSublist()));return recyclerView;}private List<String> getRandomSublist() {String[] array = Cheeses.sCheeseStrings;ArrayList<String> list = new ArrayList<String>();while (list.size() < 30) {list.add(array[new Random().nextInt(array.length)]);}return list;}}
Adapter
public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder> {private List<String> mList;private Context context;public MyAdapter(Context context, List<String> mList) {this.mList = mList;this.context = context;}@Overridepublic ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {return new ViewHolder(LayoutInflater.from(context).inflate(R.layout.list_item, parent, false));}@Overridepublic void onBindViewHolder(final ViewHolder holder, int position) {holder.mTextView.setText(mList.get(position));holder.ll_item.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {Intent intent = new Intent(context, CheeseDetailActivity.class);intent.putExtra(CheeseDetailActivity.EXTRA_NAME, mList.get(holder.getAdapterPosition()));context.startActivity(intent);}});Glide.with(holder.mImageView.getContext()).load(Cheeses.getRandomCheeseDrawable()).fitCenter().into(holder.mImageView);}@Overridepublic int getItemCount() {return mList.size();}static class ViewHolder extends RecyclerView.ViewHolder {@BindView(R.id.avatar) CircleImageView mImageView;@BindView(R.id.text) TextView mTextView;@BindView(R.id.ll_item) View ll_item;ViewHolder(View view) {super(view);ButterKnife.bind(this, view);}}}
附件列表
一个十分简洁实用的MD风格的UI主框架的更多相关文章
- Android 模仿QQ风格的 UI
本文内容 环境 演示模仿QQ风格的界面 本文主要演示的是 UI,如何模仿 QQ 风格的界面.虽然这个 UI 跟现在的QQ空间有点差别,但是也能学到很多东西. 下载 Demo 环境 Windows 7 ...
- LTUI v1.1, 一个基于lua的跨平台字符终端UI界面库
简介 LTUI是一个基于lua的跨平台字符终端UI界面库. 此框架源于xmake中图形化菜单配置的需求,类似linux kernel的menuconf去配置编译参数,因此基于curses和lua实现了 ...
- [C语言]一个很实用的服务端和客户端进行TCP通信的实例
本文给出一个很实用的服务端和客户端进行TCP通信的小例子.具体实现上非常简单,只是平时编写类似程序,具体步骤经常忘记,还要总是查,暂且将其记下来,方便以后参考. (1)客户端程序,编写一个文件clie ...
- Android 模仿QQ空间风格的 UI(转)
本文内容 环境 演示模仿QQ空间风格的UI 虽然这个 UI 跟现在的QQ空间有点差别,但是也能学到很多东西. 下载 Demo 环境 Windows 7 64 位 Eclipse ADT V22.6.2 ...
- Android 模仿QQ空间风格的 UI
本文内容 环境 演示模仿QQ空间风格的UI 虽然这个 UI 跟现在的QQ空间有点差别,但是也能学到很多东西. 下载 Demo 环境 Windows 7 64 位 Eclipse ADT V22.6.2 ...
- 各种Android UI开源框架 开源库
各种Android UI开源框架 开源库 转 https://blog.csdn.net/zhangdi_gdk2016/article/details/84643668 自己总结的Android开源 ...
- 10个顶级的CSS UI开源框架
随着CSS3和HTML5的流行,我们的WEB页面不仅需要更人性化的设计理念,而且需要更酷的页面特效和用户体验.作为开发者,我们需要了解一些宝贵的CSS UI开源框架资源,它们可以帮助我们更快更好地实现 ...
- web前端开发常用的10个高端CSS UI开源框架
web前端开发常用的10个高端CSS UI开源框架 随着人们对体验的极致追求,web页面设计也面临着新的挑战,不仅需要更人性化的设计理念,还需要设计出更酷炫的页面.作为web前端开发人员,运用开源 ...
- [转]10个顶级的CSS UI开源框架
随着CSS3和HTML5的流行,我们的WEB页面不仅需要更人性化的设计理念,而且需要更酷的页面特效和用户体验.作为开发者,我们需要了解一些宝贵的CSS UI开源框架资源,它们可以帮助我们更快更好地实现 ...
随机推荐
- Bzoj2002/洛谷P3203 [HNOI2010]弹飞绵羊(分块)
题面 Bzoj 洛谷 题解 大力分块,分块大小\(\sqrt n\),对于每一个元素记一下跳多少次能跳到下一个块,以及跳到下一个块的哪个位置,修改的时候时候只需要更新元素所在的那一块即可,然后询问也是 ...
- async await 使用笔记
JavaScript的网络请求异步的,即网络请求不会阻塞当前 js 代码的继续执行,而是通过回调的方式,网络请求的代码块中注入回调函数,当网络请求完成,会触发相应的事件,通过触发事件来执行注册的回调函 ...
- IDC、ICP、ISP区别
ICP( Internet Content Provider):网络内容服务商,即向广大用户综合提供互联网信息业务和增值业务的电信运营商.其必须具备的证书即为ICP证,如运营一个网站,需要进行备案获取 ...
- 【动态规划/多重背包问题】POJ2392-Space Elevator
方法同POJ1014-Dividing,唯一不同点在于每一种block有最大限定高度a,故要以a为关键字进行排序,使得最大高度小的在前,否则最大高度小的再后可能放不上去. #include<io ...
- python3-开发进阶Flask的基础(4)
今日内容: 上下文管理:LocalProxy对象 上下文管理: 请求上下文: request/session app上下文:app/g 第三方组件:wtforms 1.使用 ...
- 如何解决The underlying provider failed on Open问题
转自codeproject,找了半天解决办法,这个最靠谱. 我数据库用的EF做ORM,在vs里面测试的时候不会出现这个错误,用IIS就出错了.解决方法如下 Solution for "The ...
- bzoj 2733: [HNOI2012]永无乡 -- 线段树
2733: [HNOI2012]永无乡 Time Limit: 10 Sec Memory Limit: 128 MB Description 永无乡包含 n 座岛,编号从 1 到 n,每座岛都有自 ...
- bzoj 1303: [CQOI2009]中位数图 数学
1303: [CQOI2009]中位数图 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnline/ ...
- linux基础命令学习(十二)yum命令
主要功能是更方便的添加/删除/更新RPM包. 它能自动解决包的倚赖性问题. 它能便于管理大量系统的更新问题 yum list|more 列出所有包文件,可搭配grep查 ...
- javascript:window.history.forward(1);
javascript:window.history.forward(1);[转] 接下来我们要讨论的方法以后退按钮本身为中心,而不是浏览器缓存.这儿有一篇文章Rewiring the Back But ...