Android常用代码-EditText各种样式背景

底部变色直线

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:bottom="1px" android:state_focused="true">
<layer-list>
<item>
<shape>
<solid android:color="@color/colorPrimary" />
</shape>
</item>
<item android:bottom="1px">
<shape>
<solid android:color="@android:color/white" />
</shape>
</item>
</layer-list>
</item>
<item android:bottom="1px" android:state_pressed="false">
<layer-list>
<item>
<shape>
<solid android:color="#ddd" />
</shape>
</item>
<item android:bottom="1px">
<shape>
<solid android:color="@android:color/white" />
</shape>
</item>
</layer-list>
</item>
</selector>

Android常用代码-发送验证码倒计时

使用RxJava优雅的实现

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
btnVerifyCode.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
btnVerifyCode.setEnabled(false);
Observable.interval(0, 1, TimeUnit.SECONDS)
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(AndroidSchedulers.mainThread())
.limit(31)
.map(new Func1<Long, Long>() {
@Override
public Long call(Long aLong) {
return 30 - aLong;
}
})
.doOnSubscribe(new Action0() {
@Override
public void call() {
btnVerifyCode.setEnabled(false);
}
})
.doOnCompleted(new Action0() {
@Override
public void call() {
btnVerifyCode.setEnabled(true);
btnVerifyCode.setText("重新发送");
}
})
.subscribe(new Action1<Long>() {
@Override
public void call(Long aLong) {
btnVerifyCode.setText("重新发送("+aLong + " s )");
}
}, new Action1<Throwable>() {
@Override
public void call(Throwable throwable) {
ToastUtils.showCustomBgToast("获取失败,错误信息:" + throwable.getMessage() + "");
}
});
}
});

Android常用代码-底部弹出PopupWindow

关键代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/**
* 显示自定义底部弹出PopupWindow
*
* @param parent 传根布局就好了
* @param contentView PopupWindow内容
* @param bgColor 背景颜色(窗体变暗效果)
* @param focusable 是否点击空白区域取消(非全屏时可以)和返回键关闭
* @param fullScreen 是否全屏
* @param onDismissListener 取消监听
*/
public void showBottomPopupWindow(View parent, View contentView, int bgColor, boolean focusable, boolean fullScreen, PopupWindow.OnDismissListener onDismissListener) {
hideBottomDialog();
AutoUtils.auto(contentView);
popupWindow = new PopupWindow(ViewGroup.LayoutParams.MATCH_PARENT, fullScreen ? ViewGroup.LayoutParams.MATCH_PARENT : ViewGroup.LayoutParams.WRAP_CONTENT);
popupWindow.setContentView(contentView);
// 设置弹出窗体可点击
popupWindow.setFocusable(focusable);
// 设置弹出窗体的背景
popupWindow.setBackgroundDrawable(new ColorDrawable(bgColor));
if (onDismissListener != null) {
popupWindow.setOnDismissListener(onDismissListener);
}
//设置弹出窗体显示时的动画,从底部向上弹出
popupWindow.setAnimationStyle(R.style.ZzAnimationDialog);
popupWindow.showAtLocation(parent, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
}
/**
* 隐藏自定义底部弹出PopupWindow
*/
public void hideBottomDialog() {
if (popupWindow != null) {
popupWindow.dismiss();
popupWindow = null;
}
}

小常识-火车票抢票技巧

工具

  • Windows 7/8/10
  • 12306ByPass

http://www.12306bypass.com/

操作步骤

  • 如果不是VIP,先花20块成为VIP;
  • 选好出发日期;
  • 选好起始地和终点(别选反了)
  • 选好乘客、座次。
  • 选两个最中意的车次(不要多选,否则拖慢抢票速度)。
  • 选择定时抢票(提前1分钟)
  • 修改间隔时间(200ms)
  • 选择QQ通知(登录qq小号,打开qq大号聊天窗口)
  • 选择qq版本,勾选qq电话,点击获取聊天窗口。
  • 点击开始抢票。