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:
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.
I would assume this theme is some common theme, as it shows up in a LOT 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.
Related
I need to add a drop down to my app, which is running on the AppCompat theme, since we are not using the Material design components, but rather have our own design for buttons, etc.
For a simple feature, I need to use a dropdown and here I think the Exposed drop down from the Material design theme would work nicely.
However, if I'm not specifically using the MaterialComponents theme in my styles, the app will crash whenever I try to use the style on the TextInputLayout.
Is there a way of using the nice Exposed dropdown from MaterialComponents without using the entire theme (as this overrides all colors for buttons and such)? Or maybe just a simple way of getting a nice and simple dropdown otherwise. Spinners seem kinda hard to work with..
Cheers.
I've been testing my app on API 10 and a couple of views seem to to be different.
Firstly, the background of all dialog boxes seem to be black when they should be white as on the new APIS:
Secondly, the text for the the tabs are dark grey as opposed to white on the newer APIS:
How do I change the XML themes to keep it consistent?
Thanks in advance.
If you navigate to the abs_attrs.xml file in the ActionBarSherlock library, you'll see that the themes have a bunch of name-value pairs for all kinds of attributes. You need to find the name-value pairs that are used in the dialog. Usually the names are pretty self explanatory and you can see how these attributes are used in the abs_theme.xml file.
All you need to do is override (add them your app's theme) the appropriate attributes. If you haven't themed ABS before, you should read a bit of the documentation on "mirroring" http://actionbarsherlock.com/theming.html.
I have read lots of articles, here and elsewhere about customizing AlertDialogs, and those created by AlertDialog.Builder.
The approach that I'm using at the moment is injecting my AlertDialog.Builder with a ContextThemeWrapper. This ContextThemeWrapper is configured to read from a custom style that inherits from Theme.Dialog.
My customization requirements are quite straightforward:
Change the title bar background colour from the default navy/black version
Change the font type and size of both title and buttons
I've had a look in the default themes.xml and styles.xml but I don't see where to configure number 1 in particular...can someone let me know how this is done?
Also, some of the solutions I've seen involve inflating a layout and then setting this using AlertDialog.Builder.setView()...if I was to customize using this way then how do I design the views for positive and negative buttons?
Thanks
Sorry, alert dialogs are not really intended to be themed like that. They are basically the most concrete thing you can do -- a canned appearance for standard common situations.
If you want to have a dialog with a customized appearance, you should just start with the Dialog class.
How would you implement different color themes in your app?
All I can see now is plain set color onCreate every activity and control...
Also, how would you store different color schemes in xml?
Just an entries of with different names?
Thank you!
Use custom Themes, which are declared in XML. They are very similar to CSS, if you've used them before.
EDIT:
Here's a better example of changing the theme at run time
Did anyone implemented multi theme support for android app? Are there any common practices for this?
Thanks for any advice.
UPD: The main problem for now is that android's theme engine doesn't support selectors like in CSS. For example if I have two views with "background" attribute there's no way to make theme engine distinguish those ones and set different backgrounds. I can specify different style for each view but this approach lacks flexibility 'cause it's impossible to apply style for whole activity at once.
As far as I know, there is no way to set a theme to the whole application in on line of code. If you want to change the theme of an activity, you need call setTheme() in its onCreate() method, BEFORE calling setContentView. So to make it easier for you, you could do a switch on all your themes, and select one in regards of what the user has selected. Now, if you want it to apply easily to all your activities, you could make all your activities be a subclass of a custom Activity in which you would only set the theme. Activity <-- ThemeActivity <-- all your Activities