摘要:本文整合前面四篇的控件,再结合豆瓣读书的,做了一个搜索书籍和查看书籍信息的。项目依赖库书籍列表使用了和进行布局。
本文整合前面四篇的控件,再结合豆瓣读书的API,做了一个搜索书籍和查看书籍信息的Demo。
项目依赖库groovydependencies { compile fileTree(dir: "libs", include: ["*.jar"]) compile "com.android.support:design:22.2.0" compile "com.android.support:appcompat-v7:22.2.0" compile "com.android.support:cardview-v7:22.2.0" compile "com.android.support:recyclerview-v7:22.2.0" compile "com.github.bumptech.glide:glide:3.6.0" compile "de.hdodenhof:circleimageview:1.3.0" compile "com.loopj.android:android-async-http:1.4.7" compile "com.google.code.gson:gson:2.3" compile "com.afollestad:material-dialogs:0.7.6.0" }书籍列表
使用了RecyclerView和CardView进行布局。
RecyclerView参考文章:Material Design控件使用(一)
CardView参考文章:Material Design控件使用(三)
图片的显示,使用了glide,用法比较简单
java Glide.with(holder.ivBook.getContext()) .load(book.getImage()) .fitCenter() .into(holder.ivBook);搜索书籍
* 搜索按钮(FAB)点击后,使用material-dialogs显示dialog
java new MaterialDialog.Builder(getActivity()) .title(R.string.search) .input(R.string.input_hint, R.string.input_prefill, new MaterialDialog.InputCallback() { @Override public void onInput(MaterialDialog dialog, CharSequence input) { if (!TextUtils.isEmpty(input)) { doSearch(input.toString()); } } }).show();
使用android-async-http发送HTTP请求,gson解析数据
java public static void searchBooks(String name, final IBookResponse> response) { RequestParams params = new RequestParams(); params.put("q", name); params.put("start", 0); params.put("end", 50); client.get(getAbsoluteUrl("book/search"), params, new AsyncHttpResponseHandler() { @Override public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) { try { Gson gson = new Gson(); JSONObject json = new JSONObject(new String(responseBody)); JSONArray jaBooks = json.optJSONArray("books"); List
books = gson.fromJson(jaBooks.toString(), new TypeToken >() { }.getType()); response.onData(books); } catch (Exception e) { e.printStackTrace(); } } @Override public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) { } }); }
获取数据后,更新RecyclerView
java private void doSearch(String keyword) { mProgressBar.setVisibility(View.VISIBLE); Book.searchBooks(keyword, new Book.IBookResponse显示书籍信息>() { @Override public void onData(List
books) { mAdapter = new MyAdapter(getActivity(), books); mRecyclerView.setAdapter(mAdapter); mProgressBar.setVisibility(View.GONE); } }); }
使用AppBarLayout+ TabLayout+ViewPager显示书籍信息,
具体布局参考:Material Design控件使用(四)
菜单栏实现请参考:Material Design控件使用(二)
项目源码已发布到Github
APK下载地址:demo.apk
源码地址:MaterialDesignExample
本文作者: 阳春面
原文地址:http://www.aswifter.com/2015/07/02/Material-Design-Example-5/
欢迎关注我的微信公众号,分享Android 开发,IOS开发,Swift开发和互联网内容
微信号:APP开发者
文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。
转载请注明本文地址:https://www.ucloud.cn/yun/12299.html
摘要:行代码的人脸识别实践产品掘金前言很多人都认为人脸识别是一项非常难以实现的工作,看到名字就害怕,然后心怀忐忑到网上一搜,看到网上页的教程立马就放弃了。掘金最新最全的开源项目合集掘金是由整理并维护的安卓相关开源项目库集合。 安卓第三方登录之微信登录(图文详解) - Android - 掘金一、创建应用并成为开发者 1、创建应用 1)到微信开放平台管理中心,点击创建移动应用 ... 三步实现...
摘要:与老前辈使用攻略刷新篇掘金小序继使用攻略助力篇之后,一直没有更新上下拉刷新的功能实现,主要还是受限于个人现有的技术实力,总觉得没有经过实际打磨的,就不敢有上场的自信。 DrawerLayout 和 NavigationView 使用详解 - Android - 掘金Android Material Design Library 推出了很长时间,越来越多的APP使用了符合Library ...
摘要:是以后的主流设计风格,现在已经越来越多的遵循的设计规范来进行开发,是每个开发者必学的基础技术。 本人目前正在找工作,想了解我的详细情况请移步到我的 网页版简历 ,希望能得到各位的推荐,谢谢! 关于 Material Design 在这里我就不在多做介绍了,想必做Android开发的 都听过它的大名 ,甚至用过无数次了。Material Design 是以后 Android 的主流设计风...
摘要:原图加载毛玻璃的效果比较快,你的这个打开白屏好几秒。这就是系列第六篇之系列之,等。这个系列的讲解和实例都会整理在一个里,的地址去吧,我会慢慢完善的。 这篇文章其实我一直在想,是写还是不写,因为关于讲 CoordinatorLayout,AppBarLayout,CollapsingToolbarLayout,Toolbar,TabLayout 等这些控件的使用,以前写过一篇,那就是《通...
摘要:原图加载毛玻璃的效果比较快,你的这个打开白屏好几秒。这就是系列第六篇之系列之,等。这个系列的讲解和实例都会整理在一个里,的地址去吧,我会慢慢完善的。 这篇文章其实我一直在想,是写还是不写,因为关于讲 CoordinatorLayout,AppBarLayout,CollapsingToolbarLayout,Toolbar,TabLayout 等这些控件的使用,以前写过一篇,那就是《通...
阅读 2518·2021-11-25 09:43
阅读 1084·2021-11-11 16:53
阅读 1819·2021-09-04 16:45
阅读 546·2019-08-30 15:44
阅读 803·2019-08-30 13:07
阅读 370·2019-08-29 16:06
阅读 1209·2019-08-29 13:43
阅读 1893·2019-08-27 11:04