In the attributes pane, I occasionally see two attributes with the same name, where one attribute has what looks like a "paint brush" icon in front of it (for example, in the screenshot below, the text attribute). I've searched but can't find what this means or what the difference is between the attributes.
If you enter some text in the text field with the "paint brush" icon
then this attribute will be added to the xml:
tools:text="989"
this attribute, from the tools namespace (xmlns:tools="http://schemas.android.com/tools"),
is set for design time, a value you can see in the preview of the layout and it is not compiled.
If you enter some text in the text field without the "paint brush" icon then this attribute will be added to the xml:
android:text="888"
this is the attribute that will be compiled in the apk of your app and you will see when you run the app.
Related
After taking a snapshot of the layout and inspecting it with Layout Inspector, how do I find what font is used for the selected TextView or AppCompatTextView? Text and Theme property groups have no mentions of fontFamily property. However, I see the TextView has a custom font on it.
I'm running Android Studio 3.2.1
The only thing i can see about font is the typeface (text -> getTypeFaceStyle(), "bold", "normal" ...)
If the font is defined in styles, you can see the textviews style (theme) in LayoutInspector at the bottom
I'm having a play with Android Studio.
I'm trying to change the background colour. I've found how to change it but what's puzzling me is that if I substitute the definition (ie the actual hex code) of the colorAccent property I don't see the same colour.
This is the original, which uses #color/colorAccent, which ultimately is a hex code defined in the class R.color:
This is what I get when I substitute the hex code that colorAccent references:
As you can see, I get a shade of grey instead of a shade of red. Why is this?
Thanks.
[Android Studio 3.2]
It is not shade of red beacuse depend on your select.
You can change color in XML if you hardcode it.
click on side color on left of code :
then choose your color:
But if you set it like android:background="#color/colorPrimary"
you should change it in color XML
The hex value for colorAccent in the R.java doesn't refer to the color, but rather the automatically generated unique id for that XML attribute in colors.xml. As you can see, the hex values for the variables are all in-order and increasing by 1 each time.
The actual hex code for the color denoted by colorAccent is defined in colors.xml, and substituting that directly in the android:background attribute will work as you expect it to.
How to set default/fallback value in order to see something in layout preview, when attributes are set by style?
You can use Design-time view attributes.
From the documentation:
You can insert sample data in your layout preview by using the tools:
prefix instead of android: with any attribute from the Android
framework. This is useful when the attribute's value isn't populated
until runtime but you want to see the effect beforehand, in the layout
preview.
For example, if the android:text attribute value is set at runtime or
you want to see the layout with a value different than the default,
you can add tools:text to specify some text for the layout preview
only.
How i can use little letters in buttons title?
I'm creating string in res/values/strings.xml with register, but still getting Caps.
You could add android:textAllCaps="false" to the button.
The button text might be transformed to uppercase by your app's theme that applies to all buttons. Check themes/styles files for setting the attribute android:textAllCaps.
Accroding to this link
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.
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).
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