Allow Edittext To Scroll While Disabled
I have an EditText set up as follows:
Solution 1:
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.
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:
<ScrollViewandroid:layout_width="match_parent"android:layout_height="wrap_content" ><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:descendantFocusability="beforeDescendants"android:focusableInTouchMode="true"android:orientation="vertical" ><EditTextandroid:id="@+id/edittext"android:layout_width="match_parent"android:layout_height="375dp"android:ems="10"android:gravity="top" ></EditText><TextViewandroid:id="@+id/textview"android:layout_width="match_parent"android:layout_height="375dp"android:ems="10"android:gravity="top"android:visibility="gone" ></TextView><Buttonandroid:layout_width="match_parent"android:layout_height="wrap_content" /></LinearLayout></ScrollView>
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);
returntrue;
}
returnfalse;
}
});
And you can do a reverse method if you need to rewrite your text. Hope this helps.
Post a Comment for "Allow Edittext To Scroll While Disabled"