android键盘类型的,Android SetText更改键盘类型

我正在开发一个包含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格式):

android:id="@+id/activityRoot"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

>

android:id="@+id/editText1"

android:layout_width="fill_parent"

android:layout_height="wrap_content" >

android:id="@+id/textView1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="MyTextView" />

您观察到的文本更改的活动:

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");

}

});

}

}

标签:settext,android,keyboard

来源: https://codeday.me/bug/20191011/1890351.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值