重点:
onCheckIsTextEditor()
检查称为视图是一个文本编辑器,在这种情况下,它将使意义它自动显示软输入窗口。如果此视图是文本编辑器,则返回true。所以让我们改变它!然后,键盘没有出现:)
创建自己的类
import android.content.Context;
import android.util.AttributeSet;
import android.widget.EditText;
public class NoImeEditText extends EditText {
public NoImeEditText(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public boolean onCheckIsTextEditor() {
return false;
}
}
设定这样的XML
<your.package.name.NoImeEditText
android:textSize="17dp"
android:textColor="#FFF"
android:id="@+id/edit_query"
android:layout_width="match_parent"
android:layout_height="60dp" />
称之为
editText = (NoImeEditText) findViewById(R.id.edit_query);
检查重点
editText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if(hasFocus){
// show your custom key pad and do your work
Toast.makeText(getApplicationContext(), "got the focus", Toast.LENGTH_LONG).show();
}else {
Toast.makeText(getApplicationContext(), "lost the focus", Toast.LENGTH_LONG).show();
}
}
});
请解释一下你想,因为你可以使EDITTEXT无法点击,但再有没有EDITTEXT的意义因此而不是使用EditText上你可以使用TextView的究竟是什么。请解释一下你的输出 –
@ user7359831试试我的答案:) –
我想用我的键盘。我正在制作计算器,所以我不需要键盘。 – user7359831