沉浸式
View decorView = getWindow().getDecorView();//获取最大的Activity
int option=View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN|View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
decorView.setSystemUiVisibility(option);
getWindow().setStatusBarColor(Color.TRANSPARENT);//ActionBar改为透明
ActionBar supportActionBar = getSupportActionBar();
supportActionBar.hide();//代码去掉ActionBar
完全沉浸式 比如看视频
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (hasFocus&& Build.VERSION.SDK_INT>=19){
View decorView = getWindow().getDecorView();
decorView.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN|
View.SYSTEM_UI_FLAG_FULLSCREEN|
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION|
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION|
View.SYSTEM_UI_FLAG_LAYOUT_STABLE|
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
);
}
}
正则
正则语法
正则语法,用^ 开头, $结尾
\d 匹配一个数字字符。等价于[0-9]。
\D 匹配一个非数字字符。等价于[^0-9]。
\w 匹配包括下划线的任何单词字符。等价于“[A-Za-z0-9_]”。
\W 匹配任何非单词字符。等价于“[^A-Za-z0-9_]”。
* 匹配前面的子表达式零次或多次。
+ 匹配前面的子表达式一次或多次。
? 匹配前面的子表达式零次或一次。
\ 转义字符
用户名,是否只含数字与英文,字符串长度并在4~16个字符之间
^[A-Za-z0-9]{4,16}$
邮箱:xxx@163.com
/^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/
正则:
密码: 密码长度在6位到10位,必须有英文和数字
^(?!^[0-9]+$)(?!^[a-zA-Z]+$)[0-9A-Za-z]{6,10}$
解释: ?! 属于零宽断言的正向否定断言
(?!^度[0-9]+$)表示字符串不能是全问数字的字符串
(?!^[a-zA-Z]+$) 表示字符串不能全是字符.
案例
规则 正则表达式语法
一个或多个汉字 ^[\u0391-\uFFE5]+$
邮政编码 ^[1-9]\d{5}$
QQ号码 ^[1-9]\d{4,10}$
邮箱 ^[a-zA-Z_]{1,}[0-9]{0,}@(([a-zA-z0-9]-*){1,}\.){1,3}[a-zA-z\-]{1,}$
用户名(字母开头 + 数字/字母/下划线) ^[A-Za-z][A-Za-z1-9_-]+$
手机号码 ^1[3|4|5|8][0-9]\d{8}$
URL ^((http|https)://)?([\w-]+\.)+[\w-]+(/[\w-./?%&=]*)?$
18位身份证号 ^(\d{6})(18|19|20)?(\d{2})([01]\d)([0123]\d)(\d{3})(\d|X|x)?$
匹配验证
public static void main(String[] args) {
// 要验证的字符串
String str = "service@xsoftlab.net";
// 邮箱验证规则
String regEx = "[a-zA-Z_]{1,}[0-9]{0,}@(([a-zA-z0-9]-*){1,}\\.){1,3}[a-zA-z\\-]{1,}";
// 编译正则表达式
Pattern pattern = Pattern.compile(regEx);
// 忽略大小写的写法
// Pattern pat = Pattern.compile(regEx, Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(str);
// 字符串是否与正则表达式相匹配
boolean rs = matcher.matches();
System.out.println(rs);
//简写
boolean matches1 = Pattern.matches(reg, "12312");
}
SP封装
public class SpUtit {
private static SharedPreferences sp;
private static SharedPreferences.Editor editor;
private static SpUtit spUtit=null;
private SpUtit() {
sp= Myapp.getContext.getSharedPreferences("fengzhuang", Context.MODE_PRIVATE);
editor=sp.edit();
}
public static SpUtit getSpUtit(){
if (spUtit==null){
return new SpUtit();
}
return spUtit;
}
public void put(String key,Object value){
if (value instanceof String){
editor.putString(key, (String) value);
}
if (value instanceof Integer){
editor.putInt(key, (Integer) value);
}
editor.commit();
}
public SharedPreferences get(){
return sp;
}
}
Glide封装
public class GliteUtils {
private static GliteUtils gliteUtils=null;
private GliteUtils() {
}
public static GliteUtils getGliteUtils(){
if (gliteUtils==null){
return new GliteUtils();
}
return gliteUtils;
}
public void getGlite(Context context, String url, ImageView src){
Glide.with(context)
.load(url)
.placeholder(R.mipmap.ic_launcher)
.error(R.mipmap.qq)
.into(src);
}
public void getC(Context context){
Glide.get(context).clearMemory();
}
}
Retrofit 封装
public class RetrofitUtil {
private static RetrofitUtil retrofitUtil = new RetrofitUtil();
private Retrofit retrofit;
private RetrofitUtil(){
}
public synchronized static RetrofitUtil getRetrofitUtil(){
return retrofitUtil;
}
public synchronized Retrofit getRetrofit(String url){
if (retrofit==null){
return retrofit = new Retrofit.Builder()
.client(new OkHttpClient.Builder()
.addInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY)).build())
.baseUrl(url)
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.build();
}
return retrofit;
}
}
数据库封装
public class Daotutils {
private static Daotutils daotutils=null;
private DaoSession daoSession;
private Daotutils() {
DaoMaster.DevOpenHelper devOpenHelper = new DaoMaster.DevOpenHelper(Myapp.context, "day02.db");
SQLiteDatabase readableDatabase = devOpenHelper.getReadableDatabase();
DaoMaster daoMaster = new DaoMaster(readableDatabase);
daoSession=daoMaster.newSession();
}
public static Daotutils getDaotutil() {
if (daotutils==null){
synchronized (Daotutils.class){
return new Daotutils();
}
}
return daotutils;
}
public DaoSession getDaoSession() {
return daoSession;
}
}
自定义拦截器
public class BaseInterceptor implements Interceptor {
@Override
public Response intercept(Chain chain) throws IOException {
Request aa = chain.request().newBuilder().addHeader("token", "qwertyuiip[123").build();
Platform.get().log(INFO, "这是我新加的", null);
return chain.proceed(aa);
}
}