Hacker News new | ask | show | jobs
by huggyface 5122 days ago
Not really looking forward to apologizing for the weak graphical tools, however-

"Ever try to change the color of a button on Android?"

android:background="#ffee11" on the button?

Or use something like CSS variables (you know -- where CSS wants to go) and pull from a resource. Are you talking about something much more complex?

You can define a shape resource and then reference that in your button. Your button can be almost any shape and look you desire, via a shared resource file so it's easy to replicate elsewhere in your app. Making a shape occupy n-percent of the screen, or having padding left, right, above, below is trivial, and I'm predominately an NDK developer and don't even deal with this normally (but just quickly validated it. Rounded corner buttons with gradient backgrounds and specific padding occupying n-percentage of the screen).

I am left completely baffled by your complaints. There is nothing arcane about a shape XML file (it is profoundly clear, and is obviously intended to be reused so you aren't scattering disparate presentation code -- such as a button style -- throughout your code), and if you don't like that you can declare the color directly. Of course that is only one of your complaints, but if you don't understand something so elegant and trivial, I have to question the rest of your concerns.

2 comments

android:background="#ffee11" on the button?

That . . . actually works! Well, now I'm embarrassed. I had previously had to go this route http://www.androidworks.com/changing-the-android-edittext-ui... with text fields, and assumed it was the only way.

How do you get buttons to occupy a percentage of the screen (I hesitate to ask, as it's probably something similarly trivial . . . but it's been such a painful subject for me that I really want to know!)?

How do you get buttons to occupy a percentage of the screen

In a LinearLayout take a look at layout_weight -- it is the key (or rather, one of the keys) to goodness. It really is an onion, and if you can get through the crying the flexibility comes in the layers.

Oh dear! That's really not the answer I was hoping for. That's about where I gave up last time -- somewhere around a dozen nested vertical and horizontal linear layouts with various weights, gravities and alignments that still wasn't giving me quite what I wanted.

Still, for correcting me on the button background thing alone, I suspect you've added years to my life. Dunno what the online equivalent of buying you a drink is, but . . . thank you.

Android shapes are great for getting basic shapes done and is a good alternative for 9-patch images. I also like the xml layout files and it's quite easy to understand. But if you are making a more complex design you will need to get those .9.png files involved.