编程经验分享

笑看嫣红染半山,
逐风万里白云间,
逍遥此身不为客,
天地三才任平凡。

0%

GSON

GSON is a library created by Google for deserializing and serializing JSON. When using Realm with GSON 2.3.1 (latest version), you have to specify an ExclusionStrategy.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// Using the User class
public class User extends RealmObject {
private String name;
private String email;
// getters and setters left out ...
}

Gson gson = new GsonBuilder()
.setExclusionStrategies(new ExclusionStrategy() {
@Override
public boolean shouldSkipField(FieldAttributes f) {
return f.getDeclaringClass().equals(RealmObject.class);
}

@Override
public boolean shouldSkipClass(Class<?> clazz) {
return false;
}
})
.create();

String json = "{ name : 'John', email : 'john@corporation.com' }";
User user = gson.fromJson(json, User.class);

强制 Google.com 域名使用 HTTPS

虽然您可以随时自行添加 HTTPS 的前缀,但是在某些情况下网页总是会自动跳到没有加密的状态,这些状态可能出现在 Google 各个网页之间的跳转,以及搜索结果链接点击之后,这会影响您的正常使用体验,因此我们建议您强制 HTTPS 连接。
在 Chrome 浏览器上输入链接 chrome://net-internals/#hsts (可复制此地址粘贴到地址栏),回车。
左上角的下拉框选择“HSTS”(默认)

阅读全文 »

Activity使用Toolbar

一般在Activity里使用Toolbar如下:
toolbar.xml

1
2
3
4
5
6
7
8
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="?actionBarSize">
</android.support.v7.widget.Toolbar>
阅读全文 »

View pager that i created loads three pages at a time. now if i swipe from page 1 to 2 then to 3.when the third page is the current item,the first page(fragment) goes to onPause().now if i swipe to second page,1st page comes to onResume() even though the page 1 is still not visible to the user. So my question is how to distinguish between the first and second page in code?for example if i have to run a piece of code when the fragment is visible, how is that done?

阅读全文 »

前言

在谷歌发布Android Design Support Library之前,底部tab布局的实现方法有不少,我最初用的是LinearLayout,后来用过RadioGroup模拟、其它方法没有用过,虽然这些方法能达到效果,但个人一直觉得不爽。Google在2015的IO大会带来了全新的Android Design Support Library,里面包含了许多新控件,这些新控件有许多是把以前的一些第三方开源库官方化,实现起来更为方便。其中的TabLayout控件可以实现底部tab布局。

阅读全文 »