android常用功能

来源:互联网 发布:去眼下皱纹手术知乎 编辑:程序博客网 时间:2024/06/07 18:33

1.editText显示隐藏密码设置:

if (!flagPasswordSee) {                    Typeface font = Typeface.createFromAsset(getAssets(), "icomoon.ttf");                    mTvSettingPasswordSee.setTypeface(font);                    mTvSettingPasswordSee.setText("\ue656");                    mTvSettingPasswordSee.setTextColor(getResources().getColor(R.color.green_pressed));                    TransformationMethod method = HideReturnsTransformationMethod.getInstance();                    mEdtPassword.setTransformationMethod(method);                    /*Selection.setSelection(mEdtPassword.getText(), mEdtPassword.getText().length());*/                    mEdtPassword.setSelection(mEdtPassword.getText().length());                    flagPasswordSee = true;                } else {                    Typeface font = Typeface.createFromAsset(getAssets(), "icomoon.ttf");                    mTvSettingPasswordSee.setTypeface(font);                    mTvSettingPasswordSee.setText("\ue657");                    mTvSettingPasswordSee.setTextColor(getResources().getColor(R.color.font_results_details_time_color));                    TransformationMethod method = PasswordTransformationMethod.getInstance();                    mEdtPassword.setTransformationMethod(method);//                    Selection.setSelection(mEdtPassword.getText(), mEdtPassword.getText().length());                    mEdtPassword.setSelection(mEdtPassword.getText().length());                    flagPasswordSee = false;                }

2.html标记替换

 /***     * @param textView     * @param text     */    public void setPromptText(TextView textView, String text) {        if (textView == null || text == null) return;        try {            Pattern pattern = Pattern.compile("<em class=\"c-f60\">");            Matcher matcher = pattern.matcher(text);            StringBuffer sbr = new StringBuffer();            while (matcher.find()) {                matcher.appendReplacement(sbr, "<font color = '#FFA74D'>");            }            matcher.appendTail(sbr);            Pattern pattern1 = Pattern.compile("</em>");            Matcher matcher1 = pattern1.matcher(sbr.toString());            StringBuffer sbr1 = new StringBuffer();            if (matcher1.find()) {                matcher1.appendReplacement(sbr1, "</font>");            }            matcher1.appendTail(sbr1);            textView.setText(Html.fromHtml(sbr1.toString()));        } catch (Exception e) {            textView.setText(text);            return;        }    }

3.设置状态栏的颜色(沉浸式)

@Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setStatusBarColor(R.drawable.bg_header);    }    /**     * 在API 19 的机器上设置状态栏的颜色     *     * @param color 要设置的颜色     */    public void setStatusBarColor(int drawable) {        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {            SystemBarTintManager tintManager = new SystemBarTintManager(this);            tintManager.setStatusBarTintEnabled(true);            tintManager.setStatusBarTintResource(drawable);        }    }
1 0