0

Is there any way to make EditView to work sometimes as itself and sometimes as TextView (readonly, but not grayed (when I set setEnabled(false) it becomes gray which I dont like). Simply I would like to use the same form for displaying information and for editing and as for now the only solution which comes to my mind is to have two components and to play with visibility parameter of them (sometimes EditView is visible and TextView not and vice versa).

And is there any possibility to have few lines in one TextView? When I wrote

android:text="bla bla \n bla bla"

in xml code it doesn't work. :(

Steve Benett
  • 12,843
  • 7
  • 59
  • 79
user2707175
  • 1,133
  • 2
  • 17
  • 44

3 Answers3

2

Don't believe XML representation .."\n" will not reflect in Graphical representation just run your application..you will get new line don't bother. Make sure TextView is multiline too.

Rauf
  • 620
  • 1
  • 8
  • 20
  • Instead of android:text="bla bla\n ha ha" I wrote android:text="bla bla/n ha ha". This small error caused fully different behaviour. :P – user2707175 Oct 28 '13 at 12:13
1

in order to make an editext behave like a textview, just set the background to some image, or a transparent color This will remove the grayed effect. and this property

setEnabled(false)

Also set the color of the text to black

On tapping the editext, change the enabled property to true and change the background resource to some other image to show that its been edited.

You can also create your own drawable with shape rectangle and fill color white to make it look like a white box (edit box).

1

You can set text color to black or any other you want in disabled mode using android:textColor="#000000" in you xml. But if you also want EditText to hide its style and totally look like TextView, you will need to apply custom styling on your text view for this...which will unnecessarily increase you efforts.

Proffered and most robust way is to have two views i.e. TextView and EditText togather and play with their visibility.

And in your second part of question, text should go to next line ideally, if its not, then there might be some other property which is restricting it to do so...

umair.ali
  • 2,714
  • 2
  • 20
  • 30