?attr/colorPrimary support version? - android

I am in a fairly serious predicament. I have built my entire app using ?attr/colorPrimary to pick the color for background shapes, as I have devised a way to dynamically change the theme and color. This works perfectly on 5.0, but on all 4.x devices, ?attr/colorPrimary crashes the app. Why does Android studio not alert developers to this incompatibility?
Is there a support version of ?attr/colorPrimary?

colorPrimary is already part of AppCompat as of version 21 and works back to API 7. Your problem is instead with your theming code.

I believe it was added after Android Lollipop - API 21.
At least this link shows that it was added between API 20 and 21:
https://developer.android.com/sdk/api_diff/21/changes/android.R.attr.html
attr/colorPrimary just point to colorPrimary defined in current theme.
I'm not sure how you implemented your theme.. But you can create your own attr... This option is good only if you support several themes.
If you have a single theme, I believe you can replace it by a color.

API 21:
Material design style
Notifications are drawn with dark text atop white (or very light)
backgrounds to match the new material design widgets. Make sure that
all your notifications look right with the new color scheme. If your
notifications look wrong, fix them:
Use setColor() to set an accent color in a circle behind your icon
image. Update or remove assets that involve color. The system ignores
all non-alpha channels in action icons and in the main notification
icon. You should assume that these icons will be alpha-only. The
system draws notification icons in white and action icons in dark
gray.

The problem is a glitch in Android code. See this, it is not the exact same but the reason is.
In case anyone out there has this problem, I want to explain my workaround.
Remove all instances of "?attr/color(Primary, Dark, or Accent)" and attempt to mimic the effect in each individual element in each individual activity. This is not a full work around, but for me it works. Google really needs to resolve this issue. If you know a better work around, please let me know and I will accept it as the better answer as long as it works.

Related

Material Design 3: How to make Toolbars the same color as primary surface?

I'd like my Android app to have toolbars the same color as the primary surface (and the status bar -- which is already the primary surface color out of the box on a clean Android Studio project). I'm targeting Material Design 3 UI guidelines.
There are various existing answers for previous versions of android, of varying quality, that involve running down a fairly lengthy rabbit hole of styles and themes to capture errant pieces of UI in a toolbar (icons, menus &c). In various previous incarnations of android there have been theme overlays, and theme variants that produce light/light-toolbar or dark/dark-toolbar apps. But none of those hooks seem to be there for Material3 -- which by DESIGN is supposed to have same-color toolbars.
With relatively default configuration, my Toolbars are (I think) primary color background, with white text during the day, and black (primary?) text on white background at night (inverted with respect to primary and secondary surfaces). And I can't find a moral equivalent of light-toolbar light background for Day/Night themes that will hopefully respect wallpaper matched colors for those that have android 12++ (I do).
I feel like I'm missing something simple here.
Fwiw, I'm NOT using CoordinatoryLayout/AppLayout -- just a naked Toolbar, due to previous unpleasant wrangles with CoordinatorLayout and running Activites in full-screen mode, which I will be doing with this project as well. (CoordinatorLayout gives me nothing I want, and breaks a lot that I do want).
I did try setting explicit colors on the toolbar, and came running here when the icon didn't change color. (I've been down this road before, on at least three versions of Android. :-P).
The app is a freshly created (about a week old) Android app, created using Android studio with latest SDK. App themes seem to have been pointed at material 2, although all dependencies are up to date for Material 3. Hard to say; all of the Android docs tell you how to migrate old apps, not how to create new ones -- a curious omission.
Would by nice to see your code. But I was with a similar problem. According with documentation, the default value for a Toolbar background is ?attr/colorSurface and it is set on android:background. So, I solved overriding toolbar style.
<style name="Theme.Custom" parent="Theme.Material3.Dark">
<item name="toolbarStyle">#style/Theme.Custom.Toolbar</item>
</style>
<style name="Theme.Custom.Toolbar" parent="Widget.Material3.Toolbar">
<item name="android:background">#color/your_color</item>
</style>
I hope that this help you.

TimePickerDialog custom theme

I'm developping an Android app and right now I'm having an issue with a part of my UI: a TimePickerDialog. I'd like the top part of the Dialog to be orange instead of the classic
I know that I could create a custome theme, but my boss want it developp in 4.0 (API 15) so that it covers almost every device.. I don't know how to set a color with using settings covered by API 21 and up..
TimePickerDialog appearance is very different in the API levels you are testing on. The biggest redesign was probably made in Lollipop (API 21), where the default dialog has a totally different (circular) look:
If you are testing on API21+, you are probably seeing this one. The background color AFAIK can be changed by tweaking the android:color* attributes in your theme. I'm not sure which one (could be android:colorAccent, android:colorPrimary...), but it is easy to determine.
However, since you are going to deploy down to API 15, and default time picker there is quite different, I would recommend using an external library to give each user the same look and feel of Lollipop.
The most used is probably this one, and allows you to style the dialog in terms of colors and much more.
API>=21:You can define <item name="colorPrimary">xxxx</item> in your style of theme
API<21:Use libary for example material libary

android notification background color is not white on lollipop

As we known that Android lollipop force set the notification background color to white, so we can set the style of TextView according to different sdk version by putting style.xml in folder values-v21.
So here comes my question, on some third party ROMs, for example, the EMUI developed by Huawei tech co., the background of notification is not white(nearly black), by setting style to
android:TextAppearance.Material.Notification.Title
the color of the text is almost black, as a result, we cannot see the text clearly. I had been searching the internet for almost two days but find nothing helps.
I am trying to get the color of the notification background and set the text color dynamically, but I don't know how to accomplish this.
Need your help, thanks a lot.
Ok, so I just use the official API to set the notification info, that would inflate the default notification layout (status_bar_latest_event_content.xml)instead of my custom layout.
The rom changed the default background and text-color of the status_bar_latest_event_content.xml, but it wouldn't (or can't) change the custom layout.
mBuilder.setLargeIcon(combineBitmap).setContentText(notifyString).setSubText("fff");
remove the android:targetSdkVersion="21" from manifest.xml. it will work! and from this there is no prob at all in your apk it just a trick i apply this and i found colorful icon in notification and all features will remain same which u earlier use

AppCombat v21 TextAppearance on Gingerbread with DarkActionBar

i recently updated the appcombat library to integrate the material design.
But there is an issue with the style "Theme.AppCompat.Light.DarkActionBar", because if i use this style and let my TextView like:
android:textAppearance="?android:attr/textAppearanceSmall
the whole text appears invisible (or just white) on a white background
If a use the "Theme.AppCompat.Light" theme, everything is working fine.
This issue i have only on Devices running android 2.3.*
Samples: (Don't have enough reputation to post images, so you need to click)
DarkActionBar:
Light:
Any suggestions guys? Anyone tried the new appcombat library with Gingerbread?
Obviously i found out that i need to use material text appeareance, for instance:
android:textAppearance="#style/TextAppearance.AppCompat.Body1"
See also:
http://www.google.com/design/spec/style/typography.html#typography-roboto-noto

How to get the new Android progress view that is in 4.0?

I have just tried implementing a ProgressBar with the following two styles:
?android:attr/progressBarStyleLarge
?android:attr/progressBarStyleSmall
However, they are the old, vanilla progress spinners that Android has always had. See below:
I'm looking for the progress bar that comes with the 4.+ theme. It's the one that has one progress indicator rotating clockwise, and a semi-transparent indicator running counterclockwise at a slower pace. The heads then intersect at 5 points (star formation) across the circle, like the image below.
How do I get this ProgressBar in my app?
You should define a custom theme, then have it inherit from Theme.Holo in API level 11+, and from Theme for all others (or their light variants). To do so, see Select a theme based on platform version.
That way the progressBarStyleLarge attribute will be mapped to the new resource (progress_large_holo) in devices that support it. This will also change all other resources though (such as backgrounds for EditText, &c).

Categories

Resources