I understand that that Material design enforces Roboto by default when you load san-serif fonts in the UI widgets.
I also understand in order to render material design in pre-lollipop one needs appcompat UI widgets.
Do this imply that these appcompat UI widgets will render Roboto in pre-lolipop devices as well?
No, the font on pre-L is not Roboto.
you can use Libraries such as RobotoTextView, which is quite nice and easy to use, to set all of your text widgets to Roboto.
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.
So I have an app in which the user can select a color by choosing from a set of RadioButtons, I have used the ButtonTint XML attribute to color the buttons, but obviously this only works on API > 21/.
so my question is,
how to change the color of the RadioButtons on KitKat(API 19) and below?
I have tested a few methods from other stack overflow questions, but so far none have worked.
Use design support library (23.2.0 OR latest) and appcompatwidgets as below
Material Design for Pre-Lollipop Devices :
AppCompat (aka ActionBarCompat) started out as a backport of the
Android 4.0 ActionBar API for devices running on Gingerbread,
providing a common API layer on top of the backported implementation
and the framework implementation. AppCompat v21 delivers an API and
feature-set that is up-to-date with Android 5.0
Android Support Library 22.1 :
The ability to tint widgets automatically when using AppCompat is
incredibly helpful in keeping strong branding and consistency
throughout your app. This is done automatically when inflating layouts
- replacing Button with AppCompatButton, TextView with AppCompatTextView, etc. to ensure that each could support tinting. In
this release, those tint aware widgets are now publicly available,
allowing you to keep tinting support even if you need to subclass one
of the supported widgets.
This tint aware widgets are now publicly available, allowing you to keep tinting support even if you need to subclass one of the supported widgets.
From link above,
The full list of tint aware widgets at this time is:
AppCompatAutoCompleteTextView
AppCompatButton
AppCompatCheckBox
AppCompatCheckedTextView
AppCompatEditText
AppCompatMultiAutoCompleteTextView
AppCompatRadioButton
AppCompatRatingBar
AppCompatSpinner
AppCompatTextView
I'm studying Material Theme and some things don't work in version lower than 21, like ripple effect, change the status bar color and primary text color, view elevation... even I using the v7 library.
For view elevation I tried ViewCompat.setElevation(view, value) and doesn't work. Anyone knows why and how I have to do?
For the ripple effect I tried to put the attribute android:background="?android:attr/selectableItemBackground" in the XML, but even doesn't work. I want a way of do it work in any version with just a code (without have to do separate codes for 21 version and pre 21 version). Is there a way of do this? Anyone knows how?
Thanks
The deal is that Material Design is a design language, a concept used by designers to prepare consistent UI/UX. It's not 100% implemented anywhere.
Android Lollipop has implementation of things which can be helpful in creating Material Design - compilant apps. These include shadows and ripples. Lollipop doesn't have high level Material Design things, like Floating Action Button, Snackbar, floating TextView labels and others. These are available as part of Design Support Library. You can create them by yourself as well.
Both shadows and ripples can be implemented on older Android versions to some extent. For example it's possible to create an animated ripple drawable, use it as a button's background and make it react to touch events. It's not possible to make it work smoothly, because that would require running the animation and rendering in a background thread which is available only on Lollipop and Marshmallow. Another examples are the circular reveal, the elevation system (not shadows, the drawing order) and truly rounded corners of CardView.
Colored/translucent status bar is an example of a thing which is totally reserved for Lollipop and Marshmallow, because it's a part of the system and cannot be backported at all. Another example is the new transition system.
Some things are not supported even on Lollipop. For example a floating EditText's selection toolbar. It's available only on Marshmallow. SVG graphics is not 100% supported on any Android version. Vector graphics on Lollipop and Marshmallow is a kind-of-an-SVG implementation with support for popular tags and settings. If you wish to have good vector graphics in your app, it's better to use a third party SVG reader and renderer.
ViewCompat and AppCompat make things compile. It doesn't mean that these things will work and look like on Lollipop. Design Support Library adds widgets, but most of them doesn't work like they should on Lollipop. For example CardView doesn't really cut corners, shadows are drawn with gradients, states aren't really animated. The two things you mentioned are implemented like this (pseudocode):
ViewCompat.setElevation(view, value){
if(Lollipop)
view.setElevation(value);
else
// do nothing
}
and
selectableItemBackground = Lollipop ? new RippleDrawable() : grayColor
There's a bunch of Material Design implementations scattered over github. Some of them implement only one thing, like RippleDrawable or FAB. Other libraries provide quite complete suport for widgets, shadows, etc.
Google is working on Design Support library adding more and more widgets. It doesn't have ripples or shadows yet though and probably won't have them due to performance and architectural difficulties.
I have my own library as well. I was fascinated by Material Design and frustrated by lack of implementation, so I started working on my own implementation of shadows, ripples, animations, widgets and other things. It's open source, free to use and you can find it here: https://github.com/ZieIony/Carbon
Edit: RippleDrawable
You need a RippleDrawable implementation. That should be easy as the source is open. My implementation is here: https://github.com/ZieIony/Carbon/blob/master/carbon/src/main/java/carbon/drawable/RippleDrawableFroyo.java
Then create an instance with your color and style. Set it as background.
Run RippleDrawable's animation in onTouchEvent of your view.
It's much more complicated to prepare a complete ripple with borderless mode, multiple ripples, layers, drawable states and all the stuff. If you wish, you can find all of those in Carbon (except multiple ripples). It's not only xml, but also overriden methods, extended widgets, layouts, attributes and styles.
There are simple implementations of ripples on github. If it's enough for you, you can just download a library and use it. For example this one: https://github.com/balysv/material-ripple
If you'd like to use ripples inflated from xml, it's possible as well. Check out this library: https://github.com/ozodrukh/RippleDrawable
Currently, I'm using theme Theme.Sherlock.Light.DarkActionBar.
I'm applying ?android:attr/textAppearanceMedium and ?android:attr/textAppearanceSmall attributes, for the TextView used in ListView
<TextView
...
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
...
android:textAppearance="?android:attr/textAppearanceSmall" />
However, for Jelly Bean and Gingerbread, I get 2 very different effects.
Jelly Bean (Looks great!)
Gingerbread (Ergh...)
Is there any portable way I can tell, when using textAppearanceMedium and textAppearanceSmall attributes on a light background, the color should be dark. Currently, Gingerbread is using light background for its list view. Hence, the correct font color should be dark, so that text is visible.
I understand that you want to support the native look of the respective Android version and want to avoid overwriting default colors.
A "vanilla" Gingerbread version might look like the one in your screenshot, but I have also seen GUI adaptations of device manufacturers (such as Samsung TouchWiz or HTC Sense) or Custom ROMs overwriting these color values. Not only the default background colors, also text colors.
In consequence, you cannot be sure that all pre-Honeycomb versions show bright text on a white background in dropdowns, so you'd have to check the text color as well and adapt it accordingly. Checking background or foreground resources/colors of a view can be very cumbersome, but here are two approaches: https://stackoverflow.com/a/8089242/1140682 and https://stackoverflow.com/a/8848494/1140682
However, I highly suggest that you apply custom, "fixed" colors to your text and background. Since the ActionBar has only been introduced with Honeycomb, there are no ActionBar guidelines/styles for previous versions that you could violate anyway.
A good start for this is the ActionBar Style Generator that also supports Theme.Sherlock.Light.DarkActionBar. It generates all the drawables and style files for you so that your ActionBar and menus look consistent across multiple Android versions and modifications.
I'm building an Android app that should be able to run on Android 2.1 and above. The minSdkVersion is set to 7, and the targetSdkVersion is set to 14. In order to have ActionBar functionality, I am using the ActionBarSherlock library and setting the theme of the application to a derivative of Theme.Sherlock (etc.), as required.
Aside from providing an ActionBar, I notice that when I run the app on a Honeycomb/ICS device, some of the other widgets and dialogs now have a different (i.e. Holo) appearance. I want to have an ActionBar but keep the normal, non-Holo Android theme - the Holo styling does not fit well with the rest of the app. EditText views in particular look significantly different.
I see that ActionBarSherlock defines some custom themes in values-11 (Honeycomb) and values-14 (ICS), which inherit from Theme.Holo. There are also custom styles in values-14 which map the ABS styles to the native ones (since the native ActionBar is used in ICS+).
I have found that I have to do at least the following things:
Disable the custom themes for values-11 and values-14 - this stops Holo widgets/dialogs appearing.
Disable the use of the native implementation of the ActionBar for ICS+ - this stops the crashing on ICS since it relies on the native ActionBar provided as part of Holo theme. This requires modification of the library.
Disable the custom styles for values-14 - this messed with the look/styling of the compatibility ActionBar.
I am not sure if there are other issues that I have missed. Has anyone found a good way to use the non-Holo Android theme with ActionBarSherlock, without modifying the library? Are there any problems with using the compatibility ActionBar in ICS and above?