我有一个EditText活动,我只需要输入数字.
现在,我已经将EditText的输入类型定义为仅限数字,并为我的用户绘制了一个漂亮的键盘,但是我还需要确保在用户点击时不会弹出软键盘EditText.
我试图通过添加隐藏键盘通过清单
android:windowSoftInputMode="stateAlwaysHidden"
Run Code Online (Sandbox Code Playgroud)
在我的Manifest中针对特定活动,但这对我不起作用,因为只要用户点击EditText,键盘就会再次出现.
我尝试过以编程方式执行相同操作
activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
Run Code Online (Sandbox Code Playgroud)
但这也不起作用.用户单击EditText时会出现键盘.
唯一有效的方法是将EditType的InputType设置为null,如下所示:
EditText.setInputType(InputType.TYPE_NULL);
Run Code Online (Sandbox Code Playgroud)
但我不能使用它,因为它允许键盘连接到他们设备的用户在EditText字段中输入字母和其他符号,而我希望每个人都专门使用键盘在字段中输入数据.
我还应该提一下,我目前正在Android 2.1下测试我的应用程序,但我希望我的解决方案适用于所有版本.任何帮助,将不胜感激.提前致谢.
现在我正在使用onEditorActionListener处理我的EditText字段中的enter键,并查看IME_NULL的Action ID.它适用于所有用户,除了一个.她有一个Xperia Arc.
TextView.OnEditorActionListener keyListener = new TextView.OnEditorActionListener(){
public boolean onEditorAction(TextView view, int actionId, KeyEvent event) {
if(actionId == EditorInfo.IME_NULL){
if(((EditText)findViewById(view.getId())) == ((EditText)findViewById(R.id.etUser))){
((EditText) findViewById(R.id.etPass)).requestFocus();
}
if(((EditText)findViewById(view.getId())) == ((EditText)findViewById(R.id.etPass))){
logon();
}
}
return true;
}
};
Run Code Online (Sandbox Code Playgroud)
在了解了这个问题后,我尝试了另一种方法,使用onKeyListener并查找键事件ACTION_DOWN,然后检查键码是否与KEYCODE_ENTER匹配.
EditText etUserName = (EditText) findViewById(R.id.etUser);
etUserName.setOnKeyListener(new OnKeyListener() {
public boolean onKey(View view, int keyCode, KeyEvent event){
if (event.getAction() == KeyEvent.ACTION_DOWN){
switch (keyCode)
{
case KeyEvent.KEYCODE_DPAD_CENTER:
case KeyEvent.KEYCODE_ENTER:
if(((EditText)findViewById(view.getId())) == ((EditText)findViewById(R.id.etUser))){
((EditText) findViewById(R.id.etPass)).requestFocus();
}
return true;
default:
break;
}
}
return false;
}
}); …Run Code Online (Sandbox Code Playgroud) 只是想知道,我是唯一一个遇到这种"奇怪"行为的人.
在我的活动中放置EditText并将其inputType ="textPassword"设置如下:
<EditText android:text="" android:id="@+id/EditText01"
android:hint="This is a hint" android:inputType="textPassword"
android:layout_width="wrap_content" android:layout_height="wrap_content"></EditText>
Run Code Online (Sandbox Code Playgroud)
提示在单词之间显示更大/双倍的空格.
如果我删除inputType属性,它将恢复正常.我找不到有关此行为的已知问题.
BTW-如果你想知道为什么这很重要(它不是那么多)尝试将两个EditText小部件一个放在另一个之下并将其中一个的inputType设置为"textpassword"它看起来不太好.有关如何更改密码或其他edittexts以使用相同格式的任何想法?
谢谢
PS.首先在这里添加了一个问题:http://groups.google.com/group/android-developers/browse_thread/thread/88738bb8d8046f6f,但我找不到答案.
我有列表项目EditText,我不知道会有多少项目.我有一个问题,当我在输入一些文字EditText,然后向下滚动ListView,之后我已经向上滚动再次出现在我的第一个没有文字EditText,或有其他一些文本EditText的ListView.
我已经尝试过TextWatcher,并将数据保存到数组中,但问题是返回的视图位置ListView并不总是正确的,所以我从数组中丢失了一些数据.
请帮忙.
这是我的代码:
public class EfficientAdapter extends BaseAdapter {
private LayoutInflater mInflater;
public String[] Current;
ArrayList<String> MeterName, PreviousReading, Current_Reading;
JSONArray getArray_Meter_Reading;
public EfficientAdapter(Context context, JSONArray getArray_Meter_Reading) {
mInflater = LayoutInflater.from(context);
this.getArray_Meter_Reading = getArray_Meter_Reading;
MeterName = new ArrayList<String>();
PreviousReading = new ArrayList<String>();
for (int i = 0; i < getArray_Meter_Reading.length(); i++) {
try {
String Meter_Name = getArray_Meter_Reading.getJSONObject(i)
.getString("MeterName").toString();
String previous_Meter_Reading = getArray_Meter_Reading
.getJSONObject(i).getString("PrevMeterReading") …Run Code Online (Sandbox Code Playgroud) 我有一个自定义DialogPreference子类,我希望有一个RadioGroup带有三个单选按钮.前两个是RadioButton带有标题的vanilla 组件,但是对于第三个我想EditText直接放在它的右侧,所以我可以在选择该按钮时输入自定义值.
我已经尝试将第三个按钮放入水平线LinearLayout,EditText然后第三个按钮不再参与父节点RadioGroup.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RadioGroup
android:id="@+id/lactate_radio"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<RadioButton
android:id="@+id/lactate_default_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/lactate_default_value"/>
<RadioButton
android:id="@+id/lactate_calibrated_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/lactate_calibrated_value" />
<LinearLayout android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RadioButton
android:id="@+id/lactate_custom_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/lactate_custom_value"/>
<EditText
android:id="@+id/lactate_custom_value_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</RadioGroup>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

我也试过以LinearLayout编程方式添加它,但仍然有相同的行为.有没有办法做到这一点,也许是通过明确告诉父母RadioGroup关于第三个按钮或通过某种方式EditText适当地定位,而不使用水平LinearLayout?否则,我想我必须编写一个RadioButton应该是真正的派对的子类!
我知道在android中解雇键盘的代码是
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(myEditText.getWindowToken(), 0);
Run Code Online (Sandbox Code Playgroud)
如果我们触摸文本区域之外的区域而不是屏幕中的键盘,任何人都可以建议我隐藏键盘的方法.
eclipse android android-keypad ontouchlistener android-edittext
我想要edittext,它将有3行,如果edittext内容超过3行限制,那么垂直滚动条应该对用户可见.
我创建了一个自定义EditText,并onDraw()重写了它的功能.一切都工作正常(我可以在EditText中绘制任何内容),直到我想为此更改输入方法EditText并调用此函数:
setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
Run Code Online (Sandbox Code Playgroud)
无论我何时何地调用它:在调用它之后,我的自定义EditText消失,只显示原始EditText,虽然我的重写onDraw()函数,并且在其中,或者调用它的超级函数(无论我在哪里调用它) .
我也曾尝试用透明色扮演一些帖子这里建议:
setBackgroundColor(Color.TRANSPARENT)在基类,也是
paint.setColor(0x80FF0000)我Paint的目标onDraw()函数,但他们都没有效果.
编辑:我发现问题不在于设置输入类型,而是同时设置输入类型和重力EditText:
setGravity(Gravity.CENTER_HORIZONTAL);
Run Code Online (Sandbox Code Playgroud)
如果未设置其中任何一个,我的自定义视图将按预期绘制.(还有更奇怪的是):Gravity.CENTER_VERTICAL没有问题,只有Gravity.CENTER_HORIZONTAL和Gravity.CENTER.
看起来这两个设置是互斥的.这有可能吗?
android android-custom-view android-edittext android-inputtype
我有一个RecyclerView包含EditText子元素.当选EditText中的屏幕滚动时,我想隐藏软键盘.如何判断EditText屏幕上何时不再显示?是否有一些事件监听器可以附加到EditText元素上来说明?
我有一个Editext.它包含属性数字和imeOptions(actionDone).
<android.support.v7.widget.AppCompatEditText
android:id="@+id/edit_text_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:digits="1234567890abcdefghijklmnopqrstuvwxyz....."
android:hint="@string/item_name"
android:imeOptions="actionDone"
android:maxLines="1" />
Run Code Online (Sandbox Code Playgroud)
在使用数字&& imeOptions属性时未找到actionDone(Softkeyword中的Done按钮).我们只能找到不会改变焦点的输入按钮.我通过跳过digit属性尝试了它,然后imeOptions正常工作.提前致谢
android ×10
android-edittext ×10
eclipse ×1
imeoptions ×1
keyboard ×1
listview ×1
scrollview ×1