http://androiddrawableexplorer.appspot.com/
I want to be able to use these drawables inside my projects, but my projects are generated at runtime. I only use XML to define new activities, because quite frankly, I hate working with XML from within java. I'm looking for a mathod similar to this. One that doesn't use any XML to 'findByID' the component it needs. Thank you.
Drawable foo = new Drawable(bar);
You can use this :
Drawable d = getResources().getDrawable(id)
So what exactly is it that you are looking for? You want to build activities at runtime without XML? Do you want to just be able to manipulate the android drawables?
Well this is how you use the android drawables:
How to use default Android drawables
Related
I have to make a new design for an Android App, but I only have to create the visual part (native Android). The app logic would be created by another guy based on what I present to him.
My question is? How would this be managed correctly? Do I have to make the XML's of each layout? How could I show the other person my progress?
What things should I consider when doing this?
Thanks
You need to mock the app first (create a prototype) as suggested by NoChinDeluxe. Then if you guys go ahead and decide to code it, the answer to your problem is separation of responsibilities. As Jeffrey said UI work is not only about layouts, but code as well. What I would suggest is that you and the other guy get together first and define some contracts (interfaces) that will allow you guys to split the work and work in parallel. Therefore, he can create the business logic of the app without worrying about the UI implementation. You, on the other hand, will have to mock that business logic he's implementing at the beginning so it doesn't block your UI work.
you could create layout XML files for all the Activities/screens, using resources (icons, etc as suggested by #NoChinDeluxe). However since you'd want to run the mock app, you might want to also create a "throw-away" Activity that allows you navigate to different screens of the app. Here you can add a number of buttons and when you click on each button, your app shows a specific activity. This way, you will be able to show your colleague all the screens you have created. I hope this helps.
This may not be what you want to hear, but creating Android layouts isn't a design task. They are closely tied to the code, and the design of them is going to depend on how the engineer chooses to implement the app.
Here's an example. You might have a grid with 4 cells. You could use a RelativeLayout, a LinearLayout, or GridLayout, or a GridViewLayout. Which will use choose?
I'd suggest providing your engineer with mockups and graphical assets where required. Let him / her take those and create the layouts. If you want to create layouts as a (visual-only) reference for engineering, great, but it's certainly a non-optimal tool for that task.
Things You will consider when doing visual part:-
You have to work on the resource folder of your application
Layout : All Layout you have to prepare.
Drawable : Images and drawable .xml.
Inside Values folder you will find
dimen.xml : For different devices dimen you can set.
string.xml : You can store string for hint or other purpose.
style.xml : For designing or theme or custom design.
color.xml : Color which are going to used in the application.
If I want to set content view then I use:
setContentView(R.layout.test);
But when I set a theme, why do I have to add android to the beginning of R.style.x?
setTheme(android.R.style.Theme_Light);
setContentView(R.layout.test);
The android API define a huge amount of standard resources like theme, drawable, attributes, ...
When you need to refer to one of those resources : you must use android.R
android.R is a reference to the Android R.java file. It is not custom to your app. It contains a reference to every style, resource, anything that you would ever use in an Android app.
On the other hand, R.x (without the android prefix) refers to your local app. It contains specific styles, resources, etc. that have been defined for your app, and is much more specific.
So as to your question of which to use:
Use android.R if you want to reference a standard style. This would be something like android.R.style.holo. It could also be animations, but keep in mind these are not custom, these are the building blocks.
Use R.x when you are declaring something local. This will be something that you have definded, such as R.style.MyTheme or R.layout.MyLayout.
You are not forced to use android.R.style.Theme_Light you can create your theme and use R.style.myTheme.
You use android.R.* when you want to use a layout/image/attribute/etc. already built inside Android without the need to rewrite it again.
You can use android.R.* like R.x everywhere you want (they are the same thing, the difference that R.x is build with your application while android.R is already here). You can remake things, but why do more work when Google already did it for you?
I have know core java, I want to develop android apps, in few sites I saw apps in XML in few Java.Which is best and easy to use Java or XML?
I'm assuming you are talking about the UI, not the complete app:
For everything statically I use XML, because it is easy to find in the structure of your project.
Some parts you want to create dynamically and you have no other choice then to use Code. Be smart, in this, so if you have to add several Views that look the same do this
Make an XML with your views
In the loop where you are adding the several Views, inflate this xml, set your id's etc, and add them
You can have all the basics, styles etc in your XML, and still add stuff dynamically.
Maybe you want to check out some of the hello world code?
You can't build apps in XML. You use XML to define the UI and a few other things, but the logic of the app itself has to be written in Java.
Android development is in Java, but when you declare the layouts (where the buttons and so are going to be on the screen) you do that in XML.
So you have to use BOTH anyways.
XML for layout
JAVA for programming your app
I want to use a number of ShapeDrawables in my application, which are all similar, but with different colours etc. Obviously I could just define them all in separate xml files, but is there a more efficient way to have one xml definition, instantiate various objects and change the colour either in code or xml? You could perhaps do this by calling mutate() on one ShapeDrawable defined in xml, but this returns a Drawable, rather than a shape drawable.
Maybe use GradientDrawable instead of ShapeDrawable.
Actually it is possible to do what you asked for,
this post shows you how to do it.
I tried it and it works perfectly. I haven't found though how to refer to a single drawable from the list.
It seems Level lists are meant to be used into a single object to represent different states of the object. Alhtough in this case we are using it as a drawable container to avoid having many small files.
Maybe future anrdroid releases will support a dedicated drawable container.
I have made an component for Android, which uses two drawables.
Using static values for the drawables in the code, the component works but now I want to declare the values in the properties (XML) does anyone know how to do this?
*Edit;
Is there a way to do this without using the attrs.xml?
You will need to set up a res/values/attrs.xml file to declare the attributes, then go through some code to retrieve those values inside of your View's constructor. I have a sample here that demonstrates the technique.