1、TextView

Android:lineSpacingExtra="5dp"设置行间距,如”3dp”。

android:lineSpacingMultiplier="1.2"设置行间距的倍数,如”1.2″。

超出制定长度显示省略号

android:ellipsize="end"

android:maxEms="11"

android:singleLine="true"

2、CheckBox

android:id="@+id/checkbox"

android:layout_width="25dp"

android:layout_height="25dp"

android:layout_centerVertical="true"

android:layout_gravity="center_vertical"

android:layout_marginLeft="@dimen/space_10"

android:background="@drawable/checkbox"

android:button="@null"

android:checked="true" />

3、EditText

personalEditText.setFilters(new InputFilter[]{new InputFilter.LengthFilter(number)});代码设置输入字数限制

android:maxLength="10"  XML设置输入字数限制

android:background="@null"无背景

android:inputType="textMultiLine"多行文本输入

password_edit.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);密码可见

password_edit.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);密码不可见

android:windowSoftInputMode="adjustPan"  (AndroidManifest.xml文件中对应的activity里面)弹出软键盘,布局被上顶的问题

Android如何让EditText不自动获取焦点

在EditText的父级控件中找一个,设置成

android:focusable="true"

android:focusableInTouchMode="true"

更多属性详见:http://blog.csdn.net/qyf_5445/article/details/8651740

//监听EditText输入

mLoginNameEditText.addTextChangedListener(new TextWatcher() {

@Override

public void beforeTextChanged(CharSequence s, int start, int count, int after) {

}

@Override

public void onTextChanged(CharSequence s, int start, int before, int count) {

}

@Override

public void afterTextChanged(Editable s) {

}

});

带清除按钮的EidtText

public classClearEditTextextendsEditTextimplementsView.OnFocusChangeListener,TextWatcher {

/**

*删除按钮的引用

*/

privateDrawablemClearDrawable;

private booleanhasFoucs;

publicClearEditText(Context context) {

this(context, null);

}

publicClearEditText(Context context,AttributeSet attrs) {

//这里构造方法也很重要,不加这个很多属性不能再XML里面定义

this(context,attrs,android.R.attr.editTextStyle);

}

publicClearEditText(Context context,AttributeSet attrs, intdefStyle) {

super(context,attrs,defStyle);

init();

}

private voidinit() {

//获取EditText的DrawableRight,假如没有设置我们就使用默认的图片,2是获得右边的图片  顺序是左上右下(0,1,2,3,)

mClearDrawable= getCompoundDrawables()[2];

if(mClearDrawable==null) {

// throw new

// NullPointerException("You can add drawableRight attribute in XML");

mClearDrawable= getResources().getDrawable(R.mipmap.delete_account);

}

mClearDrawable.setBounds(0,0,mClearDrawable.getIntrinsicWidth(),mClearDrawable.getIntrinsicHeight());

//默认设置隐藏图标

setClearIconVisible(false);

//设置焦点改变的监听

setOnFocusChangeListener(this);

//设置输入框里面内容发生改变的监听

addTextChangedListener(this);

}

/**

*因为我们不能直接给EditText设置点击事件,所以我们用记住我们按下的位置来模拟点击事件 当我们按下的位置 在EditText的宽度-

*图标到控件右边的间距-图标的宽度 和EditText的宽度-图标到控件右边的间距之间我们就算点击了图标,竖直方向就没有考虑

*/

@Override

public booleanonTouchEvent(MotionEvent event) {

if(event.getAction() == MotionEvent.ACTION_UP) {

if(getCompoundDrawables()[2] !=null) {

booleantouchable = event.getX() > (getWidth() - getTotalPaddingRight()) && (event.getX() < ((getWidth() - getPaddingRight())));

if(touchable) {

this.setText("");

}

}

}

return super.onTouchEvent(event);

}

/**

*当ClearEditText焦点发生变化的时候,判断里面字符串长度设置清除图标的显示与隐藏

*/

@Override

public voidonFocusChange(View v, booleanhasFocus) {

this.hasFoucs= hasFocus;

if(hasFocus) {

setClearIconVisible(getText().length() >0);

}else{

setClearIconVisible(false);

}

}

/**

*设置清除图标的显示与隐藏,调用setCompoundDrawables为EditText绘制上去

*

*@paramvisible

*/

protected voidsetClearIconVisible(booleanvisible) {

Drawable right = visible ?mClearDrawable:null;

setCompoundDrawables(getCompoundDrawables()[0],getCompoundDrawables()[1],right,getCompoundDrawables()[3]);

}

/**

*当输入框里面内容发生变化的时候回调的方法

*/

@Override

public voidonTextChanged(CharSequence s, intstart, intcount, intafter) {

if(hasFoucs) {

setClearIconVisible(s.length() >0);

}

}

@Override

public voidbeforeTextChanged(CharSequence s, intstart, intcount, intafter) {

}

@Override

public voidafterTextChanged(Editable s) {

}

/**

*设置晃动动画

*/

public voidsetShakeAnimation() {

this.setAnimation(shakeAnimation(5));

}

/**

*晃动动画

*

*@paramcounts1秒钟晃动多少下

*@return

*/

public staticAnimationshakeAnimation(intcounts) {

Animation translateAnimation =newTranslateAnimation(0,10,0,0);

//设置一个循环加速器,使用传入的次数就会出现摆动的效果。

translateAnimation.setInterpolator(newCycleInterpolator(counts));

translateAnimation.setDuration(500);

returntranslateAnimation;

}

}

更多相关文章

  1. Android(安卓)API中文文档GridView
  2. Android(安卓)API中文文档GridView
  3. 【Android】自带Theme
  4. Android(安卓)layout布局属性、标签属性总结大全。
  5. Android设置去掉 外部USB存储和默认存储选项
  6. android:windowSoftInputMode
  7. Android中的时间日期选择器
  8. android 设置主题
  9. Android等宽字体

随机推荐

  1. eclipse 启动 Android SDK Content Loade
  2. Android之两种toast的实现
  3. Android adb 使用总结 (调试专用)
  4. Android TextView里显示两种颜色
  5. android com.handmark.pulltorefresh 使
  6. 用Javascript判断访问来源操作系统, 设备
  7. Android之仿iphone抖动效果
  8. 【Android开发】构建第一个APP
  9. Android7.1&8.0 audio设置音量
  10. Android - MediaPlayer