
我正在开发一个包含EditText的android应用程序.
我通过调用来控制在editText中写的内容
et.addTextChangedListener(new TextWatcher() { public voID afterTextChanged(Editable s) { String message = et.getText().toString(); if(s.toString().compareto(before)!=0){ et.setText(message); et.setSelection(et.getText().length()); } } public voID beforeTextChanged(CharSequence s, int start, int count, int after) { before = et.getText().toString(); System.out.println("After"); } public voID onTextChanged(CharSequence s, int start, int before, int count) { System.out.println("ON"); }});在afterTextChanged函数中,我使用et.setText(“ some Text”);
问题是,更改文本后,键盘也发生了变化,例如,如果打开了符号键盘,而我使用了setText,它将自动更改为qwerty.
我怎么解决这个问题?
解决方法:
我找不到您问题的直接解决方案,但是您可以做一些事情来解决您的问题!使用位于编辑文本上的文本视图(例如,您可以使用relativeLayout在编辑文本上设置文本视图),并将编辑文本字体颜色设置为白色(或编辑文本的背景颜色),以使用户看不到它是真实文本.希望此代码段对您有所帮助:
main.xml(以res / layout格式):
<?xml version="1.0" enCoding="utf-8"?><relativeLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:ID="@+ID/activityRoot" androID:layout_wIDth="fill_parent" androID:layout_height="fill_parent" > <EditText androID:ID="@+ID/editText1" androID:layout_wIDth="fill_parent" androID:layout_height="wrap_content" > <requestFocus /> </EditText> <TextVIEw androID:ID="@+ID/textVIEw1" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:text="MyTextVIEw" /></relativeLayout> 您观察到的文本更改的活动:
public class TestproGuardActivity extends Activity { EditText et; TextVIEw tv1; /** Called when the activity is first created. */ @OverrIDe public voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.main); tv1 = (TextVIEw)findVIEwByID(R.ID.textVIEw1); et = (EditText)findVIEwByID(R.ID.editText1); et.addTextChangedListener(new TextWatcher() { private String before = "hasan"; public voID afterTextChanged(Editable s) { String message = et.getText().toString(); if(s.toString().compareto(before )!=0){// et.setText(message); tv1.setText(message);// et.setSelection(et.getText().length()); } } public voID beforeTextChanged(CharSequence s, int start, int count, int after){ before = et.getText().toString(); System.out.println("After"); } public voID onTextChanged(CharSequence s, int start, int before, int count) { System.out.println("ON"); } }); }} 总结 以上是内存溢出为你收集整理的Android SetText更改键盘类型全部内容,希望文章能够帮你解决Android SetText更改键盘类型所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)