Google's Android documentation is relatively complete when it comes to classes, interfaces, and such. But I have not been able to find a complete reference of all the style-related XML -- not just backgrounds and padding and whatnot but also action bar options, etc. Does such a thing exist or is it really just scattered amongst the other docs?
It doesn't really show all of the options contained in each style in the docs, but just has a reference to the tag.
I find that using GitHub is the best bet :-\
As an addition to hwrdprkns answer, I would suggest the Android Resource Navigator for Chrome. It's an extension that allows you to type "arn" in the URL bar / omnibox and then begin searching whatever resources (XML styles) you want. When you click on any of the results it will ink you to the GitHub when you select one.
https://chrome.google.com/webstore/detail/android-resource-navigato/agoomkionjjbejegcejiefodgbckeebo
Related
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.
This is a question for Android developers but it is not a programming-related question as it affects nothing but the developer.
What conventions are the most commonly used when naming various resources like colors, drawables and strings and etc?
I have no doubts naming my layouts activity_main or layout_secondary. However, I have always doubts when naming resources mentioned previously. I never know whether I should name these resources after their use or the content. For example:
Color: dark_blue vs text_highlighted
Drawable: blue_gradient vs top_bar_background
String: welcome_to_app vs first_time_prompt
Is there any community-created resource for good practice?
Naming is pretty much personal preference. The name is perfect as long as the name indicates what the functionality of the defined thing is. Also you and any other developer using these definitions should know how what the names mean and which definition to choose. Quite easy if you are consistent with names throughout the project.
For example dark_blue is obviously a blue color while text_highlighted is the color of highlighted text. The name you should use depends on what you need: if you want to classify colors by their name take the first, if you like to abstract from the actual color take the second. For general layouts using text_highlighted will often make more sense since the actual color does not matter and the functionality (text highlight vs text regular etc.) is more important. In this example choosing between text_highlighted and text_regular is a lot more obvious than choosing between color_light_blue and color_dark_blue although they could refer to the same color. The name can help prevent errors.
Android uses prefixes for names in [android.R.drawable]
(http://developer.android.com/reference/android/R.drawable.html) for example:
btn_ for button graphics
ic_ for icon graphics
ic_menu_ for menu icons
ic_dialog_ for dialog icons
stat_ for status icons
The schema is certainly not perfect but the advantage of using prefixes that start with the most generic classification is that you can use code completion to search for specific items step by step. So color_blue_dark could be better than dark_blue_color, at least if you consider the color classification more important than the dark / light classification. The same applies to first_time_prompt. If you have a lot of prompts it would make sense to name them prompt_first_time, promt_other_time, ... If they can be classified by an activity for example that could be used as super category: mainactivity_prompt_*, secondactivity_prompt_* so you know where they belong to.
Android SDK will be a good place to start for the good practices. You can open up any sample code in the SDK and go through the code and see the variable names.
I usually name assets like colors and pictures for their content, but I will name a style or multiple state drawable for it's function.
for example:
button_On.png; button_Off.png; button.xml
That way if I want to use the same resource in multiple places it does not get confusing.
For example using a color as a text color in one style file and a background in another style file.
I am currently trying to get the look of my app right. But I am having problems figuring out how to even set up a way to change themes. For one thing, is there even a way to change styles through code? I checked the method list and I saw nothing. This leads me to my actual question; is there a way that, like CSS, in which you style the parent, and then have it trickle down but also changed depending on the View? I looked at the Android docs, and they did not show any examples of this. Hopefully someone can give me an idea as to how to accomplish this, or if its not possible, to let me know that as well. Thanks in advance.
You should be able to do this using styles and themes. I've implemented this using Jake whartons Sherlock action bar. (I'm not certain if it's necessary) It involves using the comparability library which gives you the ability to use fragments and loaders as well. Look at his democode at http://actionbarsherlock.com/download.html. Look for where themes are mentioned and you will find the information you need. In the demo app you can change the theme in the top right corner and see how it affects the activities look and feel. It also shows many of the features available and the code to write them. I have found this an invaluable resource and it should show you how to theme your app.
When I am in a Java class file, I can get context info of a certain method/attribute/etc. (in IntelliJ, this shortcut is Ctrl+Q), which is basically a short help file describing what that element does. Look at the image 1.
But when I am in an XML file, I cannot get any contextual info on any element. Look at the image 2.
How should I enable it? Do I have to download some additional Android doc (javadoc?) file?
For Android code support in Eclipse, you might want to checkout http://android-developers.blogspot.com/2011/06/new-editing-features-in-eclipse-plug-in.html.
In particular :
XML editing has been improved with new quick fixes, code completion in more file types and many “go to declaration” enhancements.
basically a short help file describing what that element does
FYI: It's called Javadoc.
For the xml:
Go to Window, Show View, Other, General, Properties.
Then, when you have opened an Android xml, you can switch to the Graphical Layout. Clicking on an element will show you it's properties in the property view. Hovering over the elements there at least will give you contextual information.
As CrazyCoder suggested, there is no way to get such contextual info because of the lack of sources to fetch such info from. Until better times...