安卓点击按钮把 安卓edittext样式输的文字在下方显示String 信息

需要在文本输入完成后触发事件,如下:reg_username = (EditText) findViewById(R.id.reg_username);reg_username.setOnFocusChangeListener(new OnFocusChangeListener() {&@Overridepublic void onFocusChange(View v, boolean hasFocus) {// TODO Auto-generated method stubif (!hasFocus) {reg_username_str = reg_username.getText().toString();IfUserExitinDB(reg_username_str);//自定义的检查文本内容的方法&&}}&});文本框重新获得焦点:reg_username.setFocusable(true);reg_username.setFocusableInTouchMode(true);reg_username.requestFocus();&editText.clearFocus(); 失去焦点editText.requestFocus();获取焦点&package cc.c;
import android.app.A
import android.os.B
import android.text.S
import android.text.S
import android.text.method.HideReturnsTransformationM
import android.text.method.PasswordTransformationM
import android.view.V
import android.view.View.OnClickL
import android.widget.B
import android.widget.EditT
* Demo描述:
* 文本输入框(EditText)切换密码的显示与隐藏
* 参考资料:
* 1 /reference/android/text/method/HideReturnsTransformationMethod.html
* 2 /reference/android/text/method/PasswordTransformationMethod.html
* 3 http://blog.csdn.net/dawanganban/article/details/
Thank you very much
public class MainActivity extends Activity {
private Button mSwitchB
private EditText mPasswordEditT
private boolean isHidden=true;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
private void init(){
mSwitchButton=(Button) findViewById(R.id.button);
mPasswordEditText=(EditText) findViewById(R.id.editText);
mSwitchButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if (isHidden) {
//设置EditText文本为可见的
mPasswordEditText.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
//设置EditText文本为隐藏的
mPasswordEditText.setTransformationMethod(PasswordTransformationMethod.getInstance());
isHidden = !isH
mPasswordEditText.postInvalidate();
//切换后将EditText光标置于末尾
CharSequence charSequence = mPasswordEditText.getText();
if (charSequence instanceof Spannable) {
Spannable spanText = (Spannable) charS
Selection.setSelection(spanText, charSequence.length());
阅读(...) 评论()Android中在EditText输入文字后同步显示在TextView-Android-第七城市
Android中在EditText输入文字后同步显示在TextView
我好像总是对控件情有独钟的O(&_&)O,近来就打算写写Android基础控件的使用,希望可以从中挖掘一些新的东西。这次的例子是从EditText中输入文字,然后在TextView中同步显示,实现实时输入输出。关键就是用OnKeyListener监听EditText的键盘输入事件。例子比较简单,直接上代码。main.xml布局:&?xml version="1.0" encoding="utf-8"?&&LinearLayout xmlns:android="/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" &
android:id="@+id/input"
android:layout_width="fill_parent"
android:layout_height="wrap_content" /&
android:id="@+id/output"
android:layout_width="fill_parent"
android:layout_height="wrap_content" /&&/LinearLayout&主Activity程序:package nbe.sense7.vinci.import android.app.Aimport android.os.Bimport android.view.KeyEimport android.view.Vimport android.widget.EditTimport android.widget.TextVpublic class EditTextDemoActivity extends Activity {
private EditText editT
private TextView textV
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
editText = (EditText)findViewById(R.id.input);
textView = (TextView)findViewById(R.id.output);
//设置EditText按键输入时的事件
editText.setOnKeyListener(new EditText.OnKeyListener(){
public boolean onKey(View arg0, int arg1, KeyEvent arg2) {
// TODO Auto-generated method stub
textView.setText(editText.getText());
return false;
}}效果图如下:从上图看,输入的是一个网址,却不会显示为一个可点击的链接。如果希望网址高亮显示出来并且可用,可以在TextView里加上Android:autoLink="all",如:
android:id="@+id/output"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:autoLink="all" /&效果图如下:只需一步,快速开始
只需一步, 快速开始
后使用快捷导航没有帐号?
总共502条微博动态微博: 1&小时前&: 5&小时前&: 6&小时前&: 昨天&11:04&: 前天&23:28&: 前天&20:12&: 前天&13:45&: 3&天前&: 4&天前&: 4&天前&: 4&天前&: 5&天前&: 5&天前&: 6&天前&: 6&天前&: 6&天前&: 7&天前&: 7&天前&: 7&天前&: 7&天前&:
查看: 115530|回复: 5
积分威望金钱
最近项目需要输入价格,但是不想让用户在小数点后面输入太多,所以我封装了一个。当用户输入小数点的时候 监听小数点后面的位数,只要大于两位就立马删掉,封装好了,直接可以拿过来用!
public static void setPricePoint(final EditText editText) {
& & & & & & & & editText.addTextChangedListener(new TextWatcher() {
& & & & & & & & & & & & @Override
& & & & & & & & & & & & public void onTextChanged(CharSequence s, int start, int before,
& & & & & & & & & & & & & & & & & & & & int count) {
& & & & & & & & & & & & & & & & if (s.toString().contains(&.&)) {
& & & & & & & & & & & & & & & & & & & & if (s.length() - 1 - s.toString().indexOf(&.&) & 2) {
& & & & & & & & & & & & & & & & & & & & & & & & s = s.toString().subSequence(0,
& & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & s.toString().indexOf(&.&) + 3);
& & & & & & & & & & & & & & & & & & & & & & & & editText.setText(s);
& & & & & & & & & & & & & & & & & & & & & & & & editText.setSelection(s.length());
& & & & & & & & & & & & & & & & & & & & }
& & & & & & & & & & & & & & & & }
& & & & & & & & & & & & & & & & if (s.toString().trim().substring(0).equals(&.&)) {
& & & & & & & & & & & & & & & & & & & & s = &0& +
& & & & & & & & & & & & & & & & & & & & editText.setText(s);
& & & & & & & & & & & & & & & & & & & & editText.setSelection(2);
& & & & & & & & & & & & & & & & }
& & & & & & & & & & & & & & & & if (s.toString().startsWith(&0&)
& & & & & & & & & & & & & & & & & & & & & & & & && s.toString().trim().length() & 1) {
& & & & & & & & & & & & & & & & & & & & if (!s.toString().substring(1, 2).equals(&.&)) {
& & & & & & & & & & & & & & & & & & & & & & & & editText.setText(s.subSequence(0, 1));
& & & & & & & & & & & & & & & & & & & & & & & & editText.setSelection(1);
& & & & & & & & & & & & & & & & & & & & & & & &
& & & & & & & & & & & & & & & & & & & & }
& & & & & & & & & & & & & & & & }
& & & & & & & & & & & & }
& & & & & & & & & & & & @Override
& & & & & & & & & & & & public void beforeTextChanged(CharSequence s, int start, int count,
& & & & & & & & & & & & & & & & & & & & int after) {
& & & & & & & & & & & & }
& & & & & & & & & & & & @Override
& & & & & & & & & & & & public void afterTextChanged(Editable s) {
& & & & & & & & & & & & & & & & // TODO Auto-generated method stub
& & & & & & & & & & & & & & & &
& & & & & & & & & & & & }
& & & & & & & & });
& & & & }复制代码
积分威望金钱
高级会员, 积分 2841, 距离下一级还需 159 积分
高级会员, 积分 2841, 距离下一级还需 159 积分
回个帖子,下班咯~
积分威望金钱
中级会员, 积分 531, 距离下一级还需 269 积分
中级会员, 积分 531, 距离下一级还需 269 积分
积分威望金钱
高级会员, 积分 2826, 距离下一级还需 174 积分
高级会员, 积分 2826, 距离下一级还需 174 积分
沙发???
积分威望金钱
中级会员, 积分 603, 距离下一级还需 197 积分
中级会员, 积分 603, 距离下一级还需 197 积分
鄙视楼下的顶帖没我快,哈哈
积分威望金钱
高级会员, 积分 2856, 距离下一级还需 144 积分
高级会员, 积分 2856, 距离下一级还需 144 积分
楼主呀,,,您太有才了。。。
社区QQ达人
使用QQ帐号登录论坛的用户
经常参与各类话题的讨论,发帖内容较有主见
长期对论坛的繁荣而不断努力,或多次提出建设性意见
活跃且尽责职守的版主
曾经为论坛做出突出贡献目前已离职的版主
为论坛做出突出贡献的会员
经常帮助其他会员答疑
积极宣传本站,为本站带来更多注册会员
积极宣传本站,为本站带来更多的用户访问量
Powered byandroid如果给TextView或EditText的email链接加下划线,并在点击在email连接上可以弹框显示 - 推酷
android如果给TextView或EditText的email链接加下划线,并在点击在email连接上可以弹框显示
如何把textview的一些文字加上背景色:
Spannable str = new SpannableString(&#fdsfdfsdfdsfd#&);
Matcher matcher = getEmailPattern().matcher((CharSequence) str);
while (matcher.find()) {
int start = matcher.start();
int end = matcher.end();
str.setSpan(new ForegroundColorSpan(0xFF1A5798), start, end,
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
textView.setText(str);
如果在TextView上把email链接找出来并加上下划线:
写一个属性类继承ClickableSpan
public class MessageBundleSpan extends ClickableSpan {
public enum LinkType {
private String mT
private MainActivity mA
public MessageBundleSpan(MainActivity activity, String text) {
if (activity == null) {
throw new NullPointerException(&activity is NULL&);
mActivity =
public void updateDrawState(TextPaint ds) {
ds.setColor(mActivity.getResources().getColor(
R.color.message_bundle_link));
ds.setUnderlineText(true);
public void onClick(View widget) {
new AlertDialog.Builder(mActivity).setTitle(&Title&).setMessage(mText)
.create().show();
&span style=&white-space:pre&& &/span&TextView textView = (TextView)findViewById(R.id.textview);
String str = &$#%$%$%$&*&*&;
textView.setText(str);
SpannableStringBuilder stringBuilder = new SpannableStringBuilder(textView.getText());
applyRegexPattern(textView, stringBuilder, getEmailPattern(), MessageBundleSpan.LinkType.EMAIL);
textView.setText(stringBuilder, TextView.BufferType.SPANNABLE);
textView.setMovementMethod(LinkMovementMethod.getInstance());
private static Pattern getEmailPattern() {
if (sharppattern == null)
sharppattern = pile(&[\\w[.-]]+@[\\w[.-]]+\\.[\\w]+&);
private void applyRegexPattern(TextView textView, SpannableStringBuilder stringBuilder, Pattern pattern, MessageBundleSpan.LinkType type) {
Matcher matcher = pattern.matcher(textView.getText().toString().toLowerCase());
while(matcher.find()) {
String text = textView.getText().toString().substring(matcher.start(), matcher.end());
stringBuilder.setSpan(new MessageBundleSpan(this, text), matcher.start(), matcher.end(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
已发表评论数()
&&登&&&陆&&
已收藏到推刊!
请填写推刊名
描述不能大于100个字符!
权限设置: 公开
仅自己可见

我要回帖

更多关于 安卓悬浮按钮 的文章

 

随机推荐