I'm trying to create transitions in my application and it looks bad since the background color of my "android:windowBackground" (white) is flashing for a few ms when I change activity.
Managed to remove it with the Translucent Theme (parent="android:Theme.Translucent.NoTitleBar"), but Translucent does not seem to be an option when using the Material theme. Is there any way to combine those themes?
Related
I've started to replace styles with the new Material3 ones (Material You) which are present in the latest Material Design Components library. However, I don't see a replacement for Widget.MaterialComponents.Toolbar.PrimarySurface (a style that handles dark mode better by not using the primary color, which looks to bright). There's Widget.Material3.Toolbar, Widget.Material3.Toolbar.Surface and Widget.Material3.Toolbar.OnSurface but I don't think any of them is a replacement.
Am I missing something here?
Widget.MaterialComponents.Toolbar.PrimarySurface style is just a combination of Widget.MaterialComponents.Toolbar.Primary and Widget.MaterialComponents.Toolbar.Surface styles for light and dark mode.
That means this style uses colorPrimary in light mode and colorSurface in dark mode.
In the Material 3 (Material you) , the default background color for the toolbar is changed from colorPrimary to colorSurface.
You can always customize these material 3 themes according to your preference.
I am developing a paint app for android by extending the View class. On onDraw method, I am drawing the background using canvas.drawColor(Color.WHITE) each time onDraw is called and drawing other stuffs on top of it.. Everything is working fine when I am in default light theme but as soon as dark theme is applied to the device, the background of my custom view is changed to black. How can I stop this?
Make sure your app's theme does not inherit from Theme.MaterialComponents.DayNight rather inherits from Theme.MaterialComponents.Light or some version of it to disable night more. If you need to use Theme.MaterialComponents.DayNight theme, then you can specify the a color on values/colors.xml and values-night/colors.xml. The app will use values-night/colors.xml colors for night theme.
Set background color to your custom view don't leave it to the default color. Android changes the default color on theme change.
another solution is to set the theme to
<style name="App.Theme" parent="Theme.MaterialComponents.Light.NoActionBar.Bridge">
but this will lead to always light theme regardless of the system/phone theme.
I'm trying to set my Action Bar color to transparent, so it will have the same color as the background and will also blend in with the gradient background.
I tried doing something like this:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#android:color/transparent</item>
</style>
When I run my app, it launches, loads the screen for one second (all rendered correctly, action bar is transparent), then crashes to the following exception:
java.lang.IllegalArgumentException: background can not be translucent: #0
Tracing to no relevant class of my project.
If I set the parameter to a solid color, everything works fine.
Can you help me with the problem? I couldn't find any solution.
Thanks.
Your app isn't crashing as a result of the ActionBar background being transparent, but as a result of your colorPrimary being transparent, in combination with using the MediaRouter lib.
MediaRouterThemeHelper.getControllerColor and MediaRouterThemeHelper.getButtonTextColor both make calls to ColorUtils.calculateContrast, which is where your IllegalArgumentException is coming from.
ColorUtils.calculateContrast needs a fully opaque color in order to correctly calculate contrast, just based on the formula being used and MediaRouterThemeHelper uses colorPrimary to determine how to theme the MediaRouter controller and button text color.
It looks like you're using a NoActionBar style, so I'm assuming you're using a Toolbar and just setting the background to be your colorPrimary. Instead you could just use #android:color/transparent directly and change your colorPrimary to something opaque.
I've recently implemented a navigation drawer in an app that I'm working on, and I've noticed it hasn't taken on my app theme Holo.Light.DarkActionBar. Shouldn't the nav drawer have the same style as this theme, which would be that light-gray background and dark gray text? Currently it has a black background with white text. How would I go about having my navigation drawer's theme consistent with the rest of the app? I don't think I can set the theme/style to the layout of the drawer nor can I do it programatically. Is this something I must do manually? If so, does anyone know the hex values for the dark gray text and light-gray background, as I can't seem to access the default resource that contains these values.
You have to theme the navigation drawer manually, it doesn't inherit the parent theme. Here's a question that contains a list of all the Holo colors: What are the default color values for the Holo theme on Android 4.0?
I'm using ActionBarSherlock, but I'm not using any kind of of other theming. My application looks fine in the layout editor, because I'm using a certain color scheme that goes well with the white background shown. Although, when I run my application on a device 2.x, 3.x or 4.x, I get a very light gray color as the background, but it's definitely not white. Am I missing something? I thought the Light theme was a light gray action bar with a white background.
The Sherlock light theme is a copy of Holo.Light, which uses a very light grey as the default background colour.
You can override it to white it you like. In your application theme (create one if you need to which extends Sherlock Light), set the following attribute:
<item name="android:windowBackground">#android:color/white</item>