允许的EditText,同时禁用滚动 [英] Allow EditText to Scroll while Disabled

查看:1978
本文介绍了允许的EditText,同时禁用滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个的EditText 设置如下:

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

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

        <EditText
            android:layout_width="match_parent"
            android:layout_height="375dp"
            android:ems="10"
            android:gravity="top">
        </EditText>

        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
    </LinearLayout>
</ScrollView>

在程序的某一点后,文本已被键入,在的EditText 变成由以下code禁用:

At a certain point in the program, after text has been typed, the EditText becomes disabled by the following code:

edittext.setFocusable(false);
edittext.setEnabled(false);

问题是,一旦的EditText 被禁用,我不能上下滚动,看看我写的东西。如何禁用更多的打字,但仍允许对什么是书面审查?

The problem is that, once the EditText is disabled, I can't scroll up and down to see what I've written. How do I disable more typing, but still allow for review of what's been written?

推荐答案

尝试设置的android:inputType下=textMultiLine的EditText 。即使我已经在评论中说:有较低API错误的,但与固定高度,也许它会工作。

Try to set android:inputType="textMultiLine" on your EditText. Even if I already said in comments: there is a bug on lower API, but with the fixed height maybe it will work.

但是,如果这也不行,你应该创建另一个视图的TextView 的EditText 并与能见度消失,如下图:

However, if this doesn't work, you should create another view as TextView with same properties of the EditText and also with visibility to gone, as follow:

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

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

        <EditText
            android:id="@+id/edittext"
            android:layout_width="match_parent"
            android:layout_height="375dp"
            android:ems="10"
            android:gravity="top" >
        </EditText>

        <TextView
            android:id="@+id/textview"
            android:layout_width="match_parent"
            android:layout_height="375dp"
            android:ems="10"
            android:gravity="top"
            android:visibility="gone" >
        </TextView>

        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
    </LinearLayout>
</ScrollView>  

然后,当你处理与 KeyEvent.ACTION_DOWN setOnKeyListener 方法和的KeyEvent。 ACTION_ENTER ,您可以将文本复制TextView的内部和删除您的EditText:

Then, when you handle the setOnKeyListener method with KeyEvent.ACTION_DOWN and KeyEvent.ACTION_ENTER, you can copy your text inside the textview and remove your edittext:

edittext.setOnKeyListener(new OnKeyListener() {
    public boolean onKey(View v, int keyCode, KeyEvent event) {
        if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
            String st = edittext.getText().toString();
            textview.setVisibility(View.VISIBLE);
            textview.setText(st);
            return true;
        }
        return false;
    }
});

你可以,如果你需要重写你的文字做一个反向的方法。结果
希望这有助于。

And you can do a reverse method if you need to rewrite your text.
Hope this helps.

这篇关于允许的EditText,同时禁用滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆