开发者

How do I use common UI styles in Android?

I am writing my little Android app. I pop up a dialog control which is a nice, non-fullscreen, rounded-corners dialog by setting android:theme="@android:style/Theme.Dialog" on the activity in my manifest. That all works just as I expected. However it is just a drab, grey-titled dialog as in this screenshot:

How do I use common UI styles in Android?

I've noticed however that a LOT of applications, when they pop up dialogs have a nice, blue-themed title as in this screen shot.

How do I use common UI styles in Android?

I would assume this theme is some common theme, as it shows up in a LO开发者_开发知识库T of different apps. I would assume it is something built in to the OS. (My phone is a Captivate with the official Froyo release). Of course it COULD be something that every developer simply re-coded on their own, but I doubt that.

Assuming that this is a common theme, how do I utilize it in my app? What changes do I need to make to my activity to have it use that theme?

Thanks in advance!


You can set your activity to use a default theme like Theme.Black. There are default themes and they are in R.style - although i'm not sure which are available to which platforms(i.e. i think the holo themes are for 3.0 and up...

http://developer.android.com/reference/android/R.style.html

see here http://developer.android.com/guide/topics/ui/themes.html for defining your own custom themes and scroll all the way down for using the "platform styles" and themes.


Rather messy (there doesn't seem to be a good reference for this), but the platform styles are defined in \platforms\android-\data\res\values\styles.xml and \platforms\android-\data\res\values\themes.xml. You can dig through those and figure out the theme/style IDs that are available at compile time.

Other than that its really just trial and error.


To make a dialog you need to extend the dialog class. And to have a nice title bar you can use:

requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);

and have your own custom title.

to have a title use:

setTitle("MyTitle");

You can also assign your custom view for the title.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜