0

I am new to Eclipse and Android development so it is quite possible I am missing something that is obvious to others. I have a basic Android project and in the graphical layout editor for Activity_Main.xml I find that I am not able to access the property dialogs for most of the TextView properties. I have included a screen capture. I expected a dialog box listing possible color choices for the text or at least an area where I could type in a hex code. I am using Eclipse - Kepler Service Release 1. Thank you.

enter image description here

webworm
  • 10,587
  • 33
  • 120
  • 217

1 Answers1

2

You have to choose a colour from a resource.

To do that, open up your Strings.xml file, and add a colour to it. Example:

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="app_name">example</string>

    <color name="PURPLE">#800080</color>

</resources>

Then in your activity_main.xml, add this property to your TextView (reference the resource):

android:textColor="@color/PURPLE"

and/or (for other widgets, such as buttons)

android:background="@color/PURPLE"

However, if you wanted the way you were doing it, you still can. After you created your color called PURPLE, you can click on the ellipsis (...) for Text Color, and then click the Color heading, and then select the color (PURPLE will be there, along with all of the other colors you create).

enter image description here


Sources:

How to change background color in android app
Web colors in an Android color xml resource file
TextView | Android Developers
Color | Android Developers
android:textSize

Community
  • 1
  • 1
Michael Yaworski
  • 13,410
  • 19
  • 69
  • 97
  • Thank you! So any color I want to use I have to manually define in the resources node within Strings.xml? Guess I am spoiled by Visual Studio. – webworm Dec 04 '13 at 21:34
  • Would the same apply to changing the Text Size property? Would I have to define what sizes to choose from? – webworm Dec 04 '13 at 21:36
  • 1
    @webworm It seems that way yeah. One of my sources has a list of all of the colors so you can just copy and paste them to yours and choose like that. I used to be spoiled by Visual Studio too lol. As for the text size, no you don't have to do that. Android has built in features and you don't need to access a resource. You just define the pixel size. Same goes for max length, etc. I'll leave another comment with specific code for that. Hold on. – Michael Yaworski Dec 04 '13 at 21:41
  • 1
    @webworm you would add these to your TextView xml properties (in activity_main.xml): http://pastie.org/8529311 – Michael Yaworski Dec 04 '13 at 21:49
  • I started typing .. `@android:color/black` and it showed up in the list but when I went to select the value it was not entered into the properties. Is the properties list just read-only? The book I am reading (Android for Programmers - Dietel) seems to indicate that values can be entered right into the properties grid. – webworm Dec 04 '13 at 21:52
  • @webworm in the grid, you should type `@color/black1` (you can select the thing that pops up for you to finish your thought) and then it will change the color and be added to the properties as well. If you're typing into the grid, leave out the `android:` part. – Michael Yaworski Dec 04 '13 at 21:55
  • Thanks Mike! Your answers have been awesome! I remain confused as to why I cannot even type into the properties value box. I tried your suggestion .. `@color/black` but it still does not save to the property. I would expect that a cursor would appear in the textbox allowing me to type a value. – webworm Dec 04 '13 at 22:03
  • @webworm No problem. And I'm not sure why not because it does with mine. Either way, you have multiple ways of doing it. If it changes the color but doesn't change any properties, then I have no idea why that is. – Michael Yaworski Dec 04 '13 at 22:07