Android之常用功能代码
16lz
2021-12-04
透明导航栏
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);//透明状态栏getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);//透明导航栏}
Toast的用法
Toast.makeText(MainActivityRegister.this, "这是一个Toast", Toast.LENGTH_SHORT).show();
检测邮箱格式类
public class CheckEmailFormat { public boolean isValidEmail(String mail) { Pattern pattern = Pattern.compile("^[A-Za-z0-9][\\w\\._]*[a-zA-Z0-9]+@[A-Za-z0-9-_]+\\.([A-Za-z]{2,4})"); Matcher mc = pattern.matcher(mail); return mc.matches(); }}
获取时间类(若要获取十二小时制的时间,只要把HH改成hh即可)
public class GetTime { public String time(){ SimpleDateFormat sDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); return sDateFormat.format(new java.util.Date()); }}
键盘相关
//强制显示键盘public void showKeyboard(EditText temp_edit_text){ InputMethodManager imm=(InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); imm.showSoftInput(temp_edit_text, InputMethodManager.SHOW_FORCED);}//强制隐藏键盘public void hideKeyboard(Button temp_button){ InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(temp_button.getWindowToken(), 0);}
检测网络是否连通类
public class InternetStatus { //用于判断网络连接是否可用 public boolean isNetworkEnable(Context temp_context) { ConnectivityManager cm = (ConnectivityManager) temp_context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info=cm.getActiveNetworkInfo(); if(info!=null&&info.isAvailable()) { return true;//网络连接可用 } else { return false;//网络连接不可用 } }}
文本框点击后获取焦点
public class EditTextFocus { public void setFocus(EditText edit_text){ edit_text.setFocusable(true); edit_text.setFocusableInTouchMode(true); edit_text.requestFocus(); }}
转自
更多相关文章
- 【阿里云镜像】切换阿里巴巴开源镜像站镜像——Debian镜像
- 【android】监听网络变化连续多个广播的问题解决
- android获取NetworkMode
- Android传感器开发基本流程
- android中的Handler
- Android获取GPS坐标:
- Android单词查找器
- android、sax解析xml
- Android(安卓)GPS获取地理位置