Trying to add Dark Mode to my app. I am mostly there, most things work as I expect after I made the required changes, however I have a problem with the Toolbar. What have I missed?
Screenshot of Toolbar issue, and layout
You're applying AppTheme to popupTheme, what does it have?
You don't usually need to make a custom one, one of the pre-made ones like ThemeOverlay.MaterialComponents.Toolbar is enough.
And actually, if you're using MaterialComponents, you don't need to apply anything to your app to make it work in Dark Mode, just use the DayNight MaterialComponents theme.
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 am currently getting started with Material components themes. The Getting Started guide mentions these themes:
Theme.MaterialComponents
Theme.MaterialComponents.NoActionBar
Theme.MaterialComponents.Light
Theme.MaterialComponents.Light.NoActionBar
Theme.MaterialComponents.Light.DarkActionBar
Theme.MaterialComponents.DayNight
Theme.MaterialComponents.DayNight.NoActionBar
Theme.MaterialComponents.DayNight.DarkActionBar
There is no description for them though. Where can I find more details about those themes or could anyone be so kind to explain them in an answer? Just for example:
What means [..].NoActionBar? If I don't want an action bar, I don't include it in my layout file, so I really don't get this.
When would I use only Theme.MaterialComponents? Or would I always use Theme.MaterialComponents.Light or Theme.MaterialComponents.DayNight?
How do these themes look like? I couldn't find any preview and don't want to try them all out by myself - could take some time with all the widgets available on Android.
What do these themes define? Only colors? Text style? Font family?
I'm certain that I won't manage to answer all of your questions exhaustively but I'll share some thoughts, maybe it will take you one or two steps further:
What means [..].NoActionBar?
You should use a theme ending with ".NoActionBar" if you don't want the runtime to add an ActionBar to the Activity, possibly because you use a Toolbar. If you choose for example Theme.MaterialComponents.Light and use a Toolbar as well, you will notice that now your app will be renderd with two ActionBars
Please note that if some theme is called "MyTheme" then a theme which is prefixed by "MyTheme." will inherit everything from "MyTheme". So Theme.MaterialComponents.Light.NoActionBar is almost the same as Theme.MaterialComponents.Light except for the ActionBar.
So if you really don't want any ActionBar you should choose the .NoActionBar version and not include a surrogate (Toolbar) in your layout files.
What do these themes define? Only colors? Text style? Font family?
They do that, but they define also sizes, margins and behavior. In addition to that, some of them have special style combos for certain widgets (like style="#style/Widget.MaterialComponents.TextInputLayout.FilledBox" for TextInputLayout)
For a deep dive into what properties can be influenced by a theme, you can take a look at the source of themes_material.xml
When would I use only Theme.MaterialComponents? Or would I always use Theme.MaterialComponents.Light or Theme.MaterialComponents.DayNight?
Since Theme.MaterialComponents is the parent theme of Theme.MaterialComponents.Light, they have much in common. The main difference is that the first assumes that your app will have a dark background (so the text should be white) whereas the second will have black text and assumes your app's background will be light.
Generally, one will try to use a certain theme as a template which then can be/ has to be customized - for example with a special accent color.
How do these themes look like?
You can get a general idea by switching from one to the other in a small sample app of your own.
It's true that there is not one single source of information (aka the android theming bible). You have already found material.io, but maybe the Styles and Themes section from developer.android.com or this blog post on DayNight — Adding a dark theme to your app will shed some more light.
I tried to run my activity in full screen mode using this method:
android:theme="#android:style/Theme.NoTitleBar.Fullscreen
But after it my all design were changed. My Edittext-s which had only a line below now become rectangles and buttons design are changed too.
How to avoid this situation?
Try this theme instead:
android:theme="#android:style/Theme.Holo.Light.NoActionBar.Fullscreen"
The theme you are applying to your Activity is old and I think even deprecated. The Holo themes are the ones you are looking for.
**I'm probably going to get flamed for this, but I have my reasons.
I'm making app has an option to switch between 3 themes (Holo Dark, Holo Light, and Holo Light with Dark ActionBar). Because of certain reasons, I used >>this<< hack to make ActionOverflow work with devices with hard menu keys using ActionBarSherlock 4.2. The problem is that whenever I have the theme set to Holo Dark or Holo Light, the height of the menu items is a rather large (about 48dp), but whenever I have it set to Holo Light with Dark Actionbar, the height of the menu items is normal (whatever normal is).
Anyone have any ideas what's making the menuitems act strange?
I've tried checking in Styles, but I'm not sure where the problem is originating from.
If you need more info, just ask :D
Got it!
I gave up soon after I posted this question, but I came back to it, played around with the ABS library, and found out the answer!
What I did was add:
<item name="dropdownListPreferredItemHeight">48dp</item>
to my styles.xml within:
<style name="ThemeDark" parent="Holo.Theme"></style>
I did this to both Dark and Light themes and it's working just fine! :D
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.