Is there an easy way to make EditText look like TextView?

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Is there an easy way to make EditText look like TextView?

Postby n5r11 » Sun May 17, 2009 2:40 pm

Hello there,

I want an EditText to look like TextView but still behave like
EditText. I've tried applying TextView style to my EditText in my
layout.xml file, like this:
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <EditText
  2.  
  3.       android:id="@+id/lipsum"
  4.  
  5.       android:text="Lorem ipsum"
  6.  
  7.       android:style="@android:style/Widget_TextView"
  8.  
  9. />
Parsed in 0.001 seconds, using GeSHi 1.0.8.4

..but I get an error within xml editor: "Error: No resource found that
matches the given name (at 'style' with value '@android:style/
Widget_TextView')." It is strange because [font=Courier New]@android:style/
Widget_TextView[/font] definitively exists - I double checked it in code via
[font=Courier New]android.R.style.Widget_TextView[/font]. Another strange thing is that I don't
get android:style offered in the xml editor while typing? There is
android:id, android:text and everything else.. but not
android:style?!

Note: I consider the hard way (making EditText look like TextView) to
be: extending EditText and overriding it's onDraw method.

Any ideas?

PS: Check out http://developer.android.com/guide/topi ... tml#styles.
Why are id and style written without android: namespace?[font=Font type] [/font]
n5r11
Junior Developer
Junior Developer
 
Posts: 11
Joined: Sun May 17, 2009 2:29 pm

Top

Postby n5r11 » Mon May 18, 2009 10:16 am

I see lot of you are viewing this.. so please say anything.. any thought would be appreciated. Thanks..
n5r11
Junior Developer
Junior Developer
 
Posts: 11
Joined: Sun May 17, 2009 2:29 pm

Postby n5r11 » Tue May 19, 2009 10:36 pm

Ok, forget it.. I'll do it the "hard" way.. Thanks
n5r11
Junior Developer
Junior Developer
 
Posts: 11
Joined: Sun May 17, 2009 2:29 pm

Postby SlumberMachine » Wed May 20, 2009 9:42 am

Well I hope you haven't given up on this thread, but here is an idea:

Why not just use textview? TextView can be made editable. I was looking at all it's properties in the official dev guild and it says right at the top that it can optionally be made to edit:

Dev Guide - TextView
SlumberMachine
Developer
Developer
 
Posts: 39
Joined: Tue Feb 24, 2009 9:00 pm

Postby n5r11 » Wed May 20, 2009 11:33 am

@SlumberMachine, that's a great observation! But, it seems that there is more to making a TextView editable than just setting android:editable="true". It has to do with the "input method" - what ever that is - and that is where the real difference between TextView and EditText lies. TextView was designed with an EditText in mind, that's for sure. One would have to look at the EditText source code and probably EditText style to see what's really going on there. Documentation is simply not enough.

I have asked the same question back at android-developers group, and got a satisfactory answer. This is what you have to do:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <EditText android:id="@+id/title" android:layout_width="fill_parent"
  2.  
  3.         style="?android:attr/textViewStyle"
  4.  
  5.         android:background="@null" android:textColor="@null"/>
Parsed in 0.001 seconds, using GeSHi 1.0.8.4


Instead of style="?android:attr/textViewStyle" you can also write style="@android:style/Widget.TextView", don't ask me why and what it means.

Here is the thread at android-developers: http://groups.google.rs/group/android-d ... a2f60fb86e
n5r11
Junior Developer
Junior Developer
 
Posts: 11
Joined: Sun May 17, 2009 2:29 pm

Postby SlumberMachine » Wed May 20, 2009 6:59 pm

Thanks for posting that, that is really good info.
SlumberMachine
Developer
Developer
 
Posts: 39
Joined: Tue Feb 24, 2009 9:00 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 4 guests