In some android classes you can set a custom layout. As far as my understanding goes, these custom layouts need certain android:ids to work.
For example, for the ListActivity a ListView with #android:id/list has to be provided and this is specified in the documentation.
What about other views? For example, I was checking the API Demos and came across
<CheckBoxPreference
android:key="child_checkbox_preference"
android:dependency="parent_checkbox_preference"
android:layout="?android:attr/preferenceLayoutChild"
android:title="#string/title_child_preference"
android:summary="#string/summary_child_preference" />
There's a layout specified for the preference. That layout seems to be preference_child.xml, in which there's #+android:id/title and #+android:id/summary, which I assume the view will use to provide the title and the summary, but is this documented anywhere?
How do I know what resource IDs I have to use so that everything automagically works?
AFAIK, there's no trick to find out but to know the documentation or open the android's id.xml and look for references.
P.S.
Your code demonstrates how to use a specific attribute out of an entire style (the use of "?"), it has nothing to do with ID's
Related
I need to get all views that have text for setting custom fonts.
I can develop a recursive method in myBaseActiviy class for getting all views with checking instanceof when programme is in OnCreate(). But I worry about the performance? I interest your idea? What should I do?
There is no best way. An approach, the one I use, is to subclass TextView, adding a new attribute to specify the font I want to use, delegating the logic to the subclass self.
I think the easiest way is to create your own TextView. It's not as hard as it sounds ;-).
This is the origional answer:
https://stackoverflow.com/a/19679639/2767703
And this is the link you'll need:
http://javatechig.com/android/using-external-fonts-in-android-view
Or if you want to set the font in the xml:
https://stackoverflow.com/a/7197867/2767703
Warning
If you are developing for Android versions lower than Android 4.0 then
you should change the code. In these versions there is a bug that
doesn't free up memory for typefaces. What you should do is create a
HashMap that allows reusage of Typefaces. You can find more in the
comments of the last link (search for the comment with the highest
upvote).
You could also use this:
https://stackoverflow.com/a/16883281/2767703
This changes the font of every text in your application. Note: You still have to look at my warning if you use this.
You can do something like this:
Add new attribute for store font in style.
Extend your view to handle this attr and set font by view when do you need.
You can find example of using and creation of new attribute for font at this link https://stackoverflow.com/a/12282315/2156937
Hope it helps.
I am in a situation like i have to generate UI Controls like Button,Switcher,Progress Bar, Label text etc based on my list Items .
I am looking for a way to generate the controls in a View and add Views with generated controls in a Layout .
Can anyone give me a proper way to do that?
Why not to use Fragments?
Google docs about this here
and little tutorial here
You may want to take a look at the Metawidget source code. The Android version of Metawidget makes extensive use of generating Views and Layouts at runtime (e.g. see org.metawidget.android.widget.widgetbuilder.AndroidWidgetBuilder). You may even find Metawidget itself will suit your needs (it's designed to be embedded into projects for use-cases such as this).
Where can I find a list of all possible items in an android style xml? It seems like a single reference document listing them and summarizing what they do would be an extremely useful thing to have bookmarked, but I can't find one anywhere.
Here you go for every attributes you want in single file: https://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/core/res/res/values/styles.xml
And If you want only attributes list then you can refer R.style xml directly but It's not well documented so It would be better to view actual source code given in above link.
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'm studying the Android SKD Documentation and I was wondering where I can find information about the XML tags' attributes that are used when defining the layout of the interface of your application, like the android:name, android:id, class: attributes of the fragment tag etc.. I can not find them in the Reference documentation, which lists only the documentation of Java classes.. Is there any specific documentation about XML tags and attributes, organized like the Java Reference docs?
The short answer is that: it is in there. The layout tags specific to a class are typically in a subclass LayoutParams for example RelativeLayout.LayoutParams. However since most classes we use are derived from some (great-great-grand-)parent class, we climb up the hierarchy to find until we find the tag we want. The simplest way is to find details the attribute your are interested in is to search for it.
If you ever find a master list, let me know. Until then I rely on IDEs like Eclipse with auto-complete features for a quick reference.