如何使Edittext无法点击

时间:2017-01-19 06:20:43

标签: android android-edittext

我想让Editext专注于我可编程告诉它并且不允许用户按下他想要的那个。这可能吗?

我试过

android:longClickable="false"
android:clickable="false"

但都没有奏效。

出于某种原因,人们认为以下内容解决了我的问题,但是那个人正在尝试使编辑文字不可编辑,我试图通过点击

使编辑文本无法集中注意力

EditText not editable

8 个答案:

答案 0 :(得分:4)

尝试

    android:focusable="false"
    android:focusableInTouchMode="false"

答案 1 :(得分:3)

我遇到了同样的问题并使用以下方法解决了这个问题:

.setEnabled(false) and .setClickable(false)

所以请将此代码用于您的代码:

et.setEnabled(false);
et.setClickable(false);

答案 2 :(得分:0)

尝试使用此代码

EditText et = (EditText) findViewById(R.id.your_edit_text);
et.setFocusable(false);
et.setClickable(true);

答案 3 :(得分:0)

在xml文件中尝试使用以下代码 -

UIButton *toggleBtn =  [UIButton buttonWithType:UIButtonTypeCustom];
[toggleBtn setFrame:CGRectMake(0, 0, 20, 20)];
[toggleBtn addTarget:self action:@selector(toggleView) forControlEvents:UIControlEventTouchUpInside];

[toggleBtn setImageEdgeInsets:((IS_IPAD)? UIEdgeInsetsMake(0,-18, 0, 6) : UIEdgeInsetsMake(0, -3, 0, -3))];

UIBarButtonItem *toggleBtnItem = [[UIBarButtonItem alloc] initWithCustomView: toggleBtn];
self.navigationItem.rightBarButtonItems = [NSArray arrayWithObjects:searchBtnItem, toggleBtnItem, nil];

在EditText上使用它。我没试过,但希望它有效。

答案 4 :(得分:0)

EditText的直接父级应该窃取焦点。例如:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:descendantFocusability="beforeDescendants"
    android:focusable="true"
    android:focusableInTouchMode="true">

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:hint="enter.." />
</LinearLayout>

答案 5 :(得分:0)

不确定你是否得到了这个答案,但我必须做同样的事情,虽然这可能不简洁,但我知道它有效:

首先将keyListener设置为null:

myEditText.setKeyListener(null);

接下来,将EditTxt的OnTouch侦听器设置为执行您想要的任何操作:

myEditText.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                if(motionEvent.getAction() == MotionEvent.ACTION_UP){
                    //Do whatever action you need to do here. 
                }
                return false;
            }
});

从那里,您只需将操作插入OnTouch侦听器ACTION_UP操作标记即可。在我的例子中,我需要弹出一个带有listview的Dialog,供他们选择,然后将相应的文本设置为EditText。

希望有所帮助。

答案 6 :(得分:0)

程序化

我遇到了同样的问题,并使用以下方法解决了该问题:

.setEnabled(false), .setClickable(false) and .setFocuseable(false)

因此将其用于您的代码:

et.setEnabled(false);
et.setClickable(false);
et.setFocuseable(false);

使用XML

android:focusable="false"

答案 7 :(得分:0)

editText.isEnabled = false // makes it`s color grey
editText.setTextColor(Color.parseColor("#DE000000")) //change color if needed
相关问题