i am new in android development, i want to ask about the meaning of this snippet of xml code android:textAppearance="?android:attr/textAppearanceLarge". Does android framework will determine by itself the size of our text and choose large text relative to their choice?
I have tried to look up from this attribute declaration, but there is nothing that explain the property that will assign to text, and i also confuse by "?android" at the start of property.
Related
I know using a resource is good for redundant uses like any label that is generic across a platforms application but are there any other benefits to using a resource instead of hard coding?
for instance I have a button that is only in one view, is there a benefit to using a string resource for the buttons text even if it is one button that is only in one place in the entire app?
Otherwise I feel like its easier to go in to the one specific view to find the button and change the text if i need to rather then scrolling through an entire resource file to find one string resource.
There is more than one reason for using strings.xml than hardcode it. Please read the localization documentation. It allows you to easily translate text into many languages as you provide.
I would like to set some specific system settings of android within my application.
Is it possible to get the text and maybe also a description of the settings resources by code?
For instance I would like to allow to change this setting:
android.provider.Settings.System.SCREEN_BRIGHTNESS
In the android settings it appears Brighness. This resource is localized as well, so I do not want to do the same thing within my appliacation.
I would like to create a button and insert the text dynamically, if possible.
If someone has a hint were to look at, please help.
Best Regards,
Patrick
android.provider.Settings.System.SCREEN_BRIGHTNESS In the android
settings it appears Brighness. This resource is localized as well, so
I do not want to do the same thing within my appliacation.
See this: Settings.System. If you want the value localized, use an integer resource in folders with language and/or locale qualifiers. See Integer Resource and Alternative Resources
I would like to create a button and insert the text dynamically, if
possible.
Define as much of the layout as possible in xml, calling setContentView() on the name of the xml file. The button can then be referenced after the call with (Button)findViewById() using the id as given in xml. You can then set text dynamically and modify the widget further in code. See Layouts and TextView setText, which works for Button since Button extends TextView.
Hope this helps.
Just start developing with android and think instead of reading a book a webinar could be better because a webinar could also teach me short ways and how an android developer thinks when writing the code but now got a problem
<CheckedTextView
android:id="#android:id/text1"
android:checkMark="?android:attr/listChoiseIndicatorMultiple"
</>
I dont understand the above code up to now see lots of different id definitions some of them was for resources and start with #resource/name, and some of those id definitions was like #+id/name just for creating a new id for the component but this time it is using android:id/text1 and I dont understand why it is using it in that manner
Besides, the checkMark thing make me confuse more what are all those ?android:attr/listChoiseIndicatorMultiple means?
Could you please explain me and show me some resource where can I find all those magic attributes so I can cope next time by myself and hope someday can answer other newbie questions
Thanks a lot in advance, and all comment will be appreciated.
Well, reading the docs has always been helpful to me:
Android Developer Site
XML Layout specific docs
#android:id/text1 is just a format used when the id has been previously defined. When you put a + in there that means the framework should create the resource id if it doesn't already exist.
It's normal to use #+id/thisid when defining a new view in a layout, and then use #id/thisid to reference the aforementioned view from another part of the layout (say, in a RelativeLayout where you need to tell one widget to be below another).
A question mark before the ID indicates that you want to access a style attribute that's defined in a style theme, rather than hard-coding the attribute.
#android:id/text1 basically this is used when you create any android component like button, layout, textviews etc.
but when you need any external component which is general for different platform like any color, image etc then you can declare it as #resource/name.
actually there is nothing different just keep one thing in mind that in #android:id/text1, id will simply work as an class name will contains other objects like textview, imageview or any other.
now if you declare #resource/name then in that also instead of id class name will be resource. actually when you will use it in java then these(#android:id/text1) will be converted into object hierarchy.
I read with interest user sunit's answer to this question about updating an EditText's hint but have been unable to find any documentation on using the method that I presume he appears to describe there: using the <selector> element in an XML layout to dynamically adjust attributes of an EditText at runtime when the element is focused/unfocused.
In my case I am actually more interested in adjusting the android:inputType element (because the hint disappears for me when the inputType is specified) but adjusting the hint would work just as well.
To be clear I know how to make this change in Java code--I'm trying to find out if there is a way to specify the behavior in XML. Thanks!
I'm afraid it isn't yet possible. <selector> is only valid to be applied in making state lists out of Drawable and Color resources, it does not yet work for Strings.
With regards to your mention of adjusting android:inputType to make the hint disappear, this is actually a known Android bug that will eventually be fixed in later versions so I wouldn't recommend building your code around this functionality as it will break when they fix it:
http://code.google.com/p/android/issues/detail?id=13895
Since you mentioned that you already know how to do this in the Java code, I won't point out how to call setHint() from within a OnFocusChangeListener ;)
Cheers.
I understand that to apply a style you have to create the textview and apply the style programmatically, which I haven't figured out how to do yet, but what can you edit on the fly. Like text color? Background color? What things can or what cannot be edited on the fly from the java. Also can it be defined in the xml and then edited in the Java or must anything you want to change or set be defined solely from the Java?
The documentation for TextView lists the XML attributes that it supports, along with the method names for those that are supported at run time. Just about everything can be changed at run time, whether or not defined in XML (including every attribute you mentioned). The run-time changes override whatever is defined in XML.