Android小知识
Android小知识
//带下划线的EditText
public class LinedEditText extends EditText {
private Paint linePaint;
private float margin;
private int paperColor;
public LinedEditText(Context paramContext, AttributeSet paramAttributeSet) {
super(paramContext, paramAttributeSet);
this.linePaint = new Paint();
}
@Override
protected void onDraw(Canvas paramCanvas) {
paramCanvas.drawColor(this.paperColor);
int i = getLineCount();// 得到总的行數
int j = getHeight();// 获得TextView的高度
int k = getLineHeight();// 获得TextView的行高
int m = j / k + 1;// 总的线数
if (i < m)
i = m;
int n = getCompoundPaddingTop();
Log.d(“wxl”, “n----” + n);
paramCanvas.drawLine(0.0F, n, getRight(), n, this.linePaint);
for (int i2 = 0;; i2++) {
if (i2 >= i) {
setPadding(10 + (int) this.margin, 0, 0, 0);
super.onDraw(paramCanvas);
paramCanvas.restore();
return;
}
n += k;
paramCanvas.drawLine(0.0F, n, getRight(), n, this.linePaint);
paramCanvas.save();
}
}
}
//关闭键盘
public static void hideSoftInput(Activity activity) {
if (activity.getCurrentFocus() != null)
((InputMethodManager) activity
.getSystemService(Context.INPUT_METHOD_SERVICE))
.hideSoftInputFromWindow(activity.getCurrentFocus()
.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
}
//界面不被弹出的键盘盖住 xml
android:windowSoftInputMode=“adjustResize”
android:windowSoftInputMode=“adjustPan|stateAlwaysVisible”
// SpannableString单击文字链接
SpannableString spannableString = new SpannableString(str);
spannableString.setSpan(new ClickableSpan() {
public void onClick(View view) {
// Intent intent = new Intent(ApkTest.this, Apk.class);
Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(“tel:”
+ “15261589767”));
startActivity(intent);
}
}, 0, str.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
TextView.setText(spannableString);
TextView.setMovementMethod(LinkMovementMethod.getInstance());
//SharedPreferences存数据
SharedPreferences sharedPreferences = getSharedPreferences(“test”, Context.MODE_PRIVATE);
Editor editor = sharedPreferences.edit();//获取编辑器
editor.putString(“name”, “张三”);
editor.putInt(“age”, 24);
editor.putBoolean(“AutoLogin”, false);
editor.commit();//提交修改
//SharedPreferences取数据
SharedPreferences sharedPreferences = getSharedPreferences(“test”, Context.MODE_PRIVATE);
//getString()第二个参数为缺省值,如果preference中不存在该key,将返回缺省值
String name = sharedPreferences.getString(“name”, “”);
int age = sharedPreferences.getInt(“age”, 1);
boolean autoLogin= sharedPreferences. getBoolean(“AutoLogin”, false);
本文地址:https://blog.csdn.net/weixin_42601615/article/details/108980120